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.9 6.8 Change-Id: I5f4c22dd5ce678f15c9c1609c4228d50a2b32a1d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
323f408be6
commit
eeead68995
@ -23,12 +23,14 @@ static const Converter *prepareConverter(QString format, Converter::Direction di
|
|||||||
: QIODevice::ReadOnly;
|
: QIODevice::ReadOnly;
|
||||||
const char *dirn = out ? "output" : "input";
|
const char *dirn = out ? "output" : "input";
|
||||||
|
|
||||||
if (stream->fileName().isEmpty())
|
bool isOpen;
|
||||||
stream->open(out ? stdout : stdin, mode);
|
|
||||||
else
|
|
||||||
stream->open(mode);
|
|
||||||
|
|
||||||
if (!stream->isOpen()) {
|
if (stream->fileName().isEmpty())
|
||||||
|
isOpen = stream->open(out ? stdout : stdin, mode);
|
||||||
|
else
|
||||||
|
isOpen = stream->open(mode);
|
||||||
|
|
||||||
|
if (!isOpen) {
|
||||||
qFatal("Could not open \"%s\" for %s: %s",
|
qFatal("Could not open \"%s\" for %s: %s",
|
||||||
qPrintable(stream->fileName()), dirn, qPrintable(stream->errorString()));
|
qPrintable(stream->fileName()), dirn, qPrintable(stream->errorString()));
|
||||||
} else if (format == "auto"_L1) {
|
} else if (format == "auto"_L1) {
|
||||||
|
@ -20,7 +20,12 @@ DragWidget::DragWidget(QWidget *parent)
|
|||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
QFile dictionaryFile(QStringLiteral(":/dictionary/words.txt"));
|
QFile dictionaryFile(QStringLiteral(":/dictionary/words.txt"));
|
||||||
dictionaryFile.open(QIODevice::ReadOnly);
|
if (!dictionaryFile.open(QIODevice::ReadOnly)) {
|
||||||
|
// This would be a build problem, as the dictionary is in the
|
||||||
|
// resource system.
|
||||||
|
qFatal("Could not open the dictionary file: %s",
|
||||||
|
qPrintable(dictionaryFile.errorString()));
|
||||||
|
}
|
||||||
QTextStream inputStream(&dictionaryFile);
|
QTextStream inputStream(&dictionaryFile);
|
||||||
|
|
||||||
int x = 5;
|
int x = 5;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user