Skip to content

Commit

Permalink
Avoid deprecated endl for QTextStream
Browse files Browse the repository at this point in the history
In Qt 5.14.0, QTextStream warns that endl is deprecated; we're supposed
to use Qt::endl instead.

Unfortunately, we still want to compile on earlier versions of Qt as
well, so we need another compatibility shim.
  • Loading branch information
gperciva committed Oct 21, 2023
1 parent 7e0eb90 commit 963f045
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts
#endif

#if(QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#define QT_ENDL Qt::endl
#else
#define QT_ENDL endl
#endif

#endif /* !COMPAT_H */
22 changes: 12 additions & 10 deletions tests/customfilesystemmodel/run-scenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ WARNINGS_ENABLE

#include <stdio.h>

#include "compat.h"

#include "../qtest-platform.h"

RunScenario::RunScenario()
Expand Down Expand Up @@ -76,8 +78,8 @@ int RunScenario::processActions(QTextStream &in)
{
QTextStream console(stdout);
console << "ERROR: Scenario file is broken; parsing died on line:"
<< endl
<< line << endl;
<< QT_ENDL
<< line << QT_ENDL;
// Don't try to recover.
QCoreApplication::exit(1);
}
Expand Down Expand Up @@ -112,8 +114,8 @@ int RunScenario::processResults(QTextStream &in)
{
QTextStream console(stdout);
console << "ERROR: Scenario file is broken; parsing died on line:"
<< endl
<< line << endl;
<< QT_ENDL
<< line << QT_ENDL;
// Don't try to recover.
QCoreApplication::exit(1);
}
Expand All @@ -138,21 +140,21 @@ int RunScenario::runScenario(const int num)
{
// Test failed!
QTextStream console(stdout);
console << "--" << endl
<< "Test failed: " << scenarioFilename << endl;
console << "--" << QT_ENDL
<< "Test failed: " << scenarioFilename << QT_ENDL;
if(result == 1)
{
console << "Model internal state does not match "
<< "desired state. Model data:" << endl;
<< "desired state. Model data:" << QT_ENDL;
printModel();
}
console << "--" << endl << endl;
console << "--" << QT_ENDL << QT_ENDL;
}
}
else
{
QTextStream console(stdout);
console << "ERROR: could not read file: " << scenarioFilename << endl;
console << "ERROR: could not read file: " << scenarioFilename << QT_ENDL;
// Don't try to recover.
QCoreApplication::exit(1);
}
Expand All @@ -175,7 +177,7 @@ void RunScenario::printDir(const QString &dirname, const int depth)
// Add indents to show the directory structure.
for(int j = 0; j < depth; j++)
console << "\t";
console << _model.fileName(index) << endl;
console << _model.fileName(index) << QT_ENDL;
// Recursively print the subdirectory.
if(_model.isDir(index))
{
Expand Down

0 comments on commit 963f045

Please sign in to comment.