Skip to content

Commit d4d647f

Browse files
jcfrusiems
authored andcommitted
chore(generator): Replace deprecated use of "endl" with "Qt::endl"
This changes the usage of the deprecated global `endl` with `Qt::endl` for compatibility with Qt 5.15.2 and above. The approach ensures that `Qt::endl` is used consistently across all versions of Qt by defining a namespaced alias for Qt versions below 5.14.0. This follows up on the approach introduced in d11fc4f ("Qt6: QTextStream compatibility (PR-120)", 2023-10-05) by explicitly using `Qt::endl` everywhere and by flipping the logic to have `Qt::endl` defined for Qt < 5.14.0 Warnings addressed: ``` /path/to/PythonQt/generator/typesystem.cpp: In function ‘QString formattedCodeHelper(QTextStream&, Indentor&, QStringList&)’: /path/to/PythonQt/generator/typesystem.cpp:1900:38: warning: ‘QTextStream& QTextStreamFunctions::endl(QTextStream&)’ is deprecated: Use Qt::endl [-Wdeprecated-declarations] 1900 | s << indentor << line << endl; | ^~~~ In file included from /path/to/Qt/5.15.2/gcc_64/include/QtCore/qdebug.h:49, from /path/to/Qt/5.15.2/gcc_64/include/QtCore/QDebug:1, from /path/to/PythonQt/generator/typesystem.h:49, from /path/to/PythonQt/generator/typesystem.cpp:42: /path/to/Qt/5.15.2/gcc_64/include/QtCore/qtextstream.h:293:75: note: declared here 293 | Q_CORE_EXPORT QT_DEPRECATED_VERSION_X(5, 15, "Use Qt::endl") QTextStream &endl(QTextStream &s); | ^~~~ ```
1 parent 71be8c7 commit d4d647f

File tree

8 files changed

+171
-181
lines changed

8 files changed

+171
-181
lines changed

generator/abstractmetabuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ static void write_reject_log_file(const QString &name, const QString &tagName,
23962396

23972397

23982398
for (int reason=0; reason<AbstractMetaBuilder::NoReason; ++reason) {
2399-
s << QString(72, '*') << endl;
2399+
s << QString(72, '*') << Qt::endl;
24002400
switch (reason) {
24012401
case AbstractMetaBuilder::NotInTypeSystem:
24022402
s << "Not in type system";
@@ -2421,21 +2421,21 @@ static void write_reject_log_file(const QString &name, const QString &tagName,
24212421
break;
24222422
}
24232423

2424-
s << endl;
2424+
s << Qt::endl;
24252425

24262426
for (QMap<QString, AbstractMetaBuilder::RejectReason>::const_iterator it = rejects.constBegin();
24272427
it != rejects.constEnd(); ++it) {
24282428
if (it.value() != reason)
24292429
continue;
24302430
if (tagName.isEmpty()) {
2431-
s << it.key() << endl;
2431+
s << it.key() << Qt::endl;
24322432
} else {
2433-
s << "<" << tagName << " name=\"" << it.key() << "\"/>" << endl;
2434-
// s << "<rejection class=\"" << it.key() << "\"/>" << endl;
2433+
s << "<" << tagName << " name=\"" << it.key() << "\"/>" << Qt::endl;
2434+
// s << "<rejection class=\"" << it.key() << "\"/>" << Qt::endl;
24352435
}
24362436
}
24372437

2438-
s << QString(72, '*') << endl << endl;
2438+
s << QString(72, '*') << Qt::endl << Qt::endl;
24392439
}
24402440

24412441
}

generator/generator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void Generator::printClasses()
9191
if (!shouldGenerate(cls))
9292
continue;
9393
write(s, cls);
94-
s << endl << endl;
94+
s << Qt::endl << Qt::endl;
9595
}
9696
}
9797

generator/setupgenerator.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,18 @@ void SetupGenerator::generate()
277277
ReportHandler::debugSparse(QString("generating: %1").arg(fileName));
278278
QTextStream &s = initFile.stream;
279279

280-
s << "#include <PythonQt.h>" << endl;
281-
s << "#include <PythonQtConversion.h>" << endl;
280+
s << "#include <PythonQt.h>" << Qt::endl;
281+
s << "#include <PythonQtConversion.h>" << Qt::endl;
282282

283283
for (int i=0; i<(list.count()+ maxClassesPerFile -1) / maxClassesPerFile; i++) {
284-
s << "#include \"" << packKey << QString::number(i) << ".h\"" << endl;
284+
s << "#include \"" << packKey << QString::number(i) << ".h\"" << Qt::endl;
285285
}
286-
s << endl;
286+
s << Qt::endl;
287287

288288
QStringList polymorphicHandlers;
289289
if (!isBuiltin) {
290290
polymorphicHandlers = writePolymorphicHandler(s, list.at(0)->package(), classes_with_polymorphic_id, list);
291-
s << endl;
291+
s << Qt::endl;
292292
}
293293

294294
QSet<QString> listRegistration;
@@ -320,14 +320,14 @@ void SetupGenerator::generate()
320320
for (QString snip : snips) {
321321
s << snip;
322322
}
323-
s << endl;
323+
s << Qt::endl;
324324

325325
// declare individual class creation functions
326-
s << "void PythonQt_init_" << initName << "(PyObject* module) {" << endl;
326+
s << "void PythonQt_init_" << initName << "(PyObject* module) {" << Qt::endl;
327327

328328
for (const AbstractMetaClass* cls : list) {
329329
if (cls->qualifiedCppName().contains("Ssl")) {
330-
s << "#ifndef QT_NO_SSL" << endl;
330+
s << "#ifndef QT_NO_SSL" << Qt::endl;
331331
}
332332
AbstractMetaFunctionList ctors = cls->queryFunctions(AbstractMetaClass::Constructors
333333
| AbstractMetaClass::WasVisible
@@ -358,28 +358,28 @@ void SetupGenerator::generate()
358358
operatorCodes = "0";
359359
}
360360
if (cls->isQObject()) {
361-
s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
361+
s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << Qt::endl;
362362
} else if (cls->isGlobalNamespace()) {
363-
s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << packageName << "\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << endl;
363+
s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << packageName << "\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << Qt::endl;
364364
} else {
365365
QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():"";
366-
s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl;
366+
s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << packageName <<"\", PythonQtCreateObject<PythonQtWrapper_" << cls->name() << ">" << shellCreator << ", module, " << operatorCodes <<");" << Qt::endl;
367367
}
368368
for (AbstractMetaClass* interface : cls->interfaces()) {
369369
// the interface might be our own class... (e.g. QPaintDevice)
370370
if (interface->qualifiedCppName() != cls->qualifiedCppName()) {
371-
s << "PythonQt::self()->addParentClass(\""<< cls->qualifiedCppName() << "\", \"" << interface->qualifiedCppName() << "\",PythonQtUpcastingOffset<" << cls->qualifiedCppName() <<","<<interface->qualifiedCppName()<<">());" << endl;
371+
s << "PythonQt::self()->addParentClass(\""<< cls->qualifiedCppName() << "\", \"" << interface->qualifiedCppName() << "\",PythonQtUpcastingOffset<" << cls->qualifiedCppName() <<","<<interface->qualifiedCppName()<<">());" << Qt::endl;
372372
}
373373
}
374374
if (cls->qualifiedCppName().contains("Ssl")) {
375-
s << "#endif" << endl;
375+
s << "#endif" << Qt::endl;
376376
}
377377
}
378-
s << endl;
378+
s << Qt::endl;
379379
for (QString handler : polymorphicHandlers) {
380-
s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << endl;
380+
s << "PythonQt::self()->addPolymorphicHandler(\""<< handler << "\", polymorphichandler_" << handler << ");" << Qt::endl;
381381
}
382-
s << endl;
382+
s << Qt::endl;
383383

384384
#if QT_VERSION < QT_VERSION_CHECK(5,14,0)
385385
QStringList list = listRegistration.toList();
@@ -389,16 +389,16 @@ void SetupGenerator::generate()
389389
list.sort();
390390
for(auto &&name: list) {
391391
if (name.contains("Ssl")) {
392-
s << "#ifndef QT_NO_SSL" << endl;
392+
s << "#ifndef QT_NO_SSL" << Qt::endl;
393393
}
394-
s << name << endl;
394+
s << name << Qt::endl;
395395
if (name.contains("Ssl")) {
396-
s << "#endif" << endl;
396+
s << "#endif" << Qt::endl;
397397
}
398398
}
399399

400400
s << "}";
401-
s << endl;
401+
s << Qt::endl;
402402
}
403403
}
404404
}
@@ -440,21 +440,21 @@ QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QStrin
440440
handlers.append(handler);
441441

442442
s << "static void* polymorphichandler_" << handler
443-
<< "(const void *ptr, const char **class_name)" << endl
444-
<< "{" << endl
445-
<< " Q_ASSERT(ptr != nullptr);" << endl
443+
<< "(const void *ptr, const char **class_name)" << Qt::endl
444+
<< "{" << Qt::endl
445+
<< " Q_ASSERT(ptr != nullptr);" << Qt::endl
446446
<< " " << cls->qualifiedCppName() << " *object = ("
447-
<< cls->qualifiedCppName() << " *)ptr;" << endl;
447+
<< cls->qualifiedCppName() << " *)ptr;" << Qt::endl;
448448
}
449449

450450
// For each, add case label
451451
QString polyId = clazz->typeEntry()->polymorphicIdValue();
452452
s << " if ("
453453
<< polyId.replace("%1", "object")
454-
<< ") {" << endl
455-
<< " *class_name = \"" << clazz->name() << "\";" << endl
456-
<< " return (" << clazz->qualifiedCppName() << "*)object;" << endl
457-
<< " }" << endl;
454+
<< ") {" << Qt::endl
455+
<< " *class_name = \"" << clazz->name() << "\";" << Qt::endl
456+
<< " return (" << clazz->qualifiedCppName() << "*)object;" << Qt::endl
457+
<< " }" << Qt::endl;
458458
} else {
459459
QString warning = QString("class '%1' inherits from polymorphic class '%2', but has no polymorphic id set")
460460
.arg(clazz->name())
@@ -467,8 +467,8 @@ QStringList SetupGenerator::writePolymorphicHandler(QTextStream &s, const QStrin
467467

468468
// Close the function if it has been opened
469469
if (!first) {
470-
s << " return nullptr;" << endl
471-
<< "}" << endl;
470+
s << " return nullptr;" << Qt::endl
471+
<< "}" << Qt::endl;
472472
}
473473
}
474474

generator/shellgenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void ShellGenerator::writeInclude(QTextStream &stream, const Include &inc)
432432
stream << ">";
433433
else
434434
stream << "\"";
435-
stream << endl;
435+
stream << Qt::endl;
436436
}
437437

438438
const AbstractMetaClass* ShellGenerator::setCurrentScope(const AbstractMetaClass* scope)

0 commit comments

Comments
 (0)