Skip to content

Commit 72e6a5f

Browse files
dangelogQt Cherry-pick Bot
authored and
Qt Cherry-pick Bot
committed
Examples: fix a couple of nodiscard warnings from QFile::open
In one case, the code simply checked for isOpen afterwards; refactor it to use QFile::open's result. In another case, a file was opened from the resource system, so add a check. Pick-to: 6.8 Change-Id: I5f4c22dd5ce678f15c9c1609c4228d50a2b32a1d Reviewed-by: Thiago Macieira <[email protected]> (cherry picked from commit eeead68) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
1 parent 005e2c7 commit 72e6a5f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

examples/corelib/serialization/convert/main.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ static const Converter *prepareConverter(QString format, Converter::Direction di
2323
: QIODevice::ReadOnly;
2424
const char *dirn = out ? "output" : "input";
2525

26+
bool isOpen;
27+
2628
if (stream->fileName().isEmpty())
27-
stream->open(out ? stdout : stdin, mode);
29+
isOpen = stream->open(out ? stdout : stdin, mode);
2830
else
29-
stream->open(mode);
31+
isOpen = stream->open(mode);
3032

31-
if (!stream->isOpen()) {
33+
if (!isOpen) {
3234
qFatal("Could not open \"%s\" for %s: %s",
3335
qPrintable(stream->fileName()), dirn, qPrintable(stream->errorString()));
3436
} else if (format == "auto"_L1) {

examples/widgets/draganddrop/draggabletext/dragwidget.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ DragWidget::DragWidget(QWidget *parent)
2020
: QWidget(parent)
2121
{
2222
QFile dictionaryFile(QStringLiteral(":/dictionary/words.txt"));
23-
dictionaryFile.open(QIODevice::ReadOnly);
23+
if (!dictionaryFile.open(QIODevice::ReadOnly)) {
24+
// This would be a build problem, as the dictionary is in the
25+
// resource system.
26+
qFatal("Could not open the dictionary file: %s",
27+
qPrintable(dictionaryFile.errorString()));
28+
}
2429
QTextStream inputStream(&dictionaryFile);
2530

2631
int x = 5;

0 commit comments

Comments
 (0)