summaryrefslogtreecommitdiffstats
path: root/examples/qtconcurrent
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2025-01-11 12:27:24 +0200
committerAhmad Samir <[email protected]>2025-01-22 19:53:25 +0200
commite9f726db844ec52c96b10eb5328e09208b49a0e7 (patch)
treec4f4cdcf5495081b3bde12f9cc1b16a6726f3bda /examples/qtconcurrent
parent3b95bfe7c7b918bfececd9734780aa9e2f91ec02 (diff)
examples: check return value of QFile::open() calls
QFile::open() is marked [[nodiscard]]. Change-Id: I0fa884b329a47c4ad59f40d66b5fbc38f3a5648e Reviewed-by: Friedemann Kleint <[email protected]>
Diffstat (limited to 'examples/qtconcurrent')
-rw-r--r--examples/qtconcurrent/wordcount/main.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp
index b157aabe47c..4369f7995d6 100644
--- a/examples/qtconcurrent/wordcount/main.cpp
+++ b/examples/qtconcurrent/wordcount/main.cpp
@@ -20,7 +20,11 @@ WordCount singleThreadedWordCount(const QStringList &files)
WordCount wordCount;
for (const QString &file : files) {
QFile f(file);
- f.open(QIODevice::ReadOnly);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning().noquote() << "Failed to open file:" << QDir::toNativeSeparators(file)
+ << ":" << f.errorString();
+ return {};
+ }
QTextStream textStream(&f);
while (!textStream.atEnd()) {
const auto words = textStream.readLine().split(' ', Qt::SkipEmptyParts);
@@ -37,7 +41,11 @@ WordCount singleThreadedWordCount(const QStringList &files)
WordCount countWords(const QString &file)
{
QFile f(file);
- f.open(QIODevice::ReadOnly);
+ if (!f.open(QIODevice::ReadOnly)) {
+ qWarning().noquote() << "Failed to open file:" << QDir::toNativeSeparators(file)
+ << ":" << f.errorString();
+ return {};
+ }
QTextStream textStream(&f);
WordCount wordCount;