Skip to content

Commit 510bc3c

Browse files
committed
kconfig: qconf: replace deprecated QString::sprintf() with QTextStream
QString::sprintf() is deprecated in the latest Qt version, and spawns a lot of warnings: HOSTCXX scripts/kconfig/qconf.o scripts/kconfig/qconf.cc: In member function ‘void ConfigInfoView::menuInfo()’: scripts/kconfig/qconf.cc:1090:61: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations] 1090 | head += QString().sprintf("<a href=\"s%s\">", sym->name); | ^ In file included from /usr/include/qt5/QtGui/qkeysequence.h:44, from /usr/include/qt5/QtWidgets/qaction.h:44, from /usr/include/qt5/QtWidgets/QAction:1, from scripts/kconfig/qconf.cc:7: /usr/include/qt5/QtCore/qstring.h:382:14: note: declared here 382 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); | ^~~~~~~ scripts/kconfig/qconf.cc:1099:60: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations] 1099 | head += QString().sprintf("<a href=\"s%s\">", sym->name); | ^ In file included from /usr/include/qt5/QtGui/qkeysequence.h:44, from /usr/include/qt5/QtWidgets/qaction.h:44, from /usr/include/qt5/QtWidgets/QAction:1, from scripts/kconfig/qconf.cc:7: /usr/include/qt5/QtCore/qstring.h:382:14: note: declared here 382 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); | ^~~~~~~ scripts/kconfig/qconf.cc:1127:90: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations] 1127 | debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno); | ^ In file included from /usr/include/qt5/QtGui/qkeysequence.h:44, from /usr/include/qt5/QtWidgets/qaction.h:44, from /usr/include/qt5/QtWidgets/QAction:1, from scripts/kconfig/qconf.cc:7: /usr/include/qt5/QtCore/qstring.h:382:14: note: declared here 382 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); | ^~~~~~~ scripts/kconfig/qconf.cc: In member function ‘QString ConfigInfoView::debug_info(symbol*)’: scripts/kconfig/qconf.cc:1150:68: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations] 1150 | debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name); | ^ In file included from /usr/include/qt5/QtGui/qkeysequence.h:44, from /usr/include/qt5/QtWidgets/qaction.h:44, from /usr/include/qt5/QtWidgets/QAction:1, from scripts/kconfig/qconf.cc:7: /usr/include/qt5/QtCore/qstring.h:382:14: note: declared here 382 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); | ^~~~~~~ scripts/kconfig/qconf.cc: In static member function ‘static void ConfigInfoView::expr_print_help(void*, symbol*, const char*)’: scripts/kconfig/qconf.cc:1225:59: warning: ‘QString& QString::sprintf(const char*, ...)’ is deprecated: Use asprintf(), arg() or QTextStream instead [-Wdeprecated-declarations] 1225 | *text += QString().sprintf("<a href=\"s%s\">", sym->name); | ^ In file included from /usr/include/qt5/QtGui/qkeysequence.h:44, from /usr/include/qt5/QtWidgets/qaction.h:44, from /usr/include/qt5/QtWidgets/QAction:1, from scripts/kconfig/qconf.cc:7: /usr/include/qt5/QtCore/qstring.h:382:14: note: declared here 382 | QString &sprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); | ^~~~~~~ The documentation also says: "Warning: We do not recommend using QString::asprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe." Use QTextStream as suggested. Reported-by: Robert Crawford <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 68fd110 commit 510bc3c

File tree

1 file changed

+62
-54
lines changed

1 file changed

+62
-54
lines changed

scripts/kconfig/qconf.cc

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,106 +1076,114 @@ void ConfigInfoView::symbolInfo(void)
10761076
void ConfigInfoView::menuInfo(void)
10771077
{
10781078
struct symbol* sym;
1079-
QString head, debug, help;
1079+
QString info;
1080+
QTextStream stream(&info);
10801081

10811082
sym = _menu->sym;
10821083
if (sym) {
10831084
if (_menu->prompt) {
1084-
head += "<big><b>";
1085-
head += print_filter(_menu->prompt->text);
1086-
head += "</b></big>";
1085+
stream << "<big><b>";
1086+
stream << print_filter(_menu->prompt->text);
1087+
stream << "</b></big>";
10871088
if (sym->name) {
1088-
head += " (";
1089+
stream << " (";
10891090
if (showDebug())
1090-
head += QString().sprintf("<a href=\"s%s\">", sym->name);
1091-
head += print_filter(sym->name);
1091+
stream << "<a href=\"s" << sym->name << "\">";
1092+
stream << print_filter(sym->name);
10921093
if (showDebug())
1093-
head += "</a>";
1094-
head += ")";
1094+
stream << "</a>";
1095+
stream << ")";
10951096
}
10961097
} else if (sym->name) {
1097-
head += "<big><b>";
1098+
stream << "<big><b>";
10981099
if (showDebug())
1099-
head += QString().sprintf("<a href=\"s%s\">", sym->name);
1100-
head += print_filter(sym->name);
1100+
stream << "<a href=\"s" << sym->name << "\">";
1101+
stream << print_filter(sym->name);
11011102
if (showDebug())
1102-
head += "</a>";
1103-
head += "</b></big>";
1103+
stream << "</a>";
1104+
stream << "</b></big>";
11041105
}
1105-
head += "<br><br>";
1106+
stream << "<br><br>";
11061107

11071108
if (showDebug())
1108-
debug = debug_info(sym);
1109+
stream << debug_info(sym);
1110+
11091111
} else if (_menu->prompt) {
1110-
head += "<big><b>";
1111-
head += print_filter(_menu->prompt->text);
1112-
head += "</b></big><br><br>";
1112+
stream << "<big><b>";
1113+
stream << print_filter(_menu->prompt->text);
1114+
stream << "</b></big><br><br>";
11131115
if (showDebug()) {
11141116
if (_menu->prompt->visible.expr) {
1115-
debug += "&nbsp;&nbsp;dep: ";
1116-
expr_print(_menu->prompt->visible.expr, expr_print_help, &debug, E_NONE);
1117-
debug += "<br><br>";
1117+
stream << "&nbsp;&nbsp;dep: ";
1118+
expr_print(_menu->prompt->visible.expr,
1119+
expr_print_help, &stream, E_NONE);
1120+
stream << "<br><br>";
11181121
}
11191122
}
11201123
}
11211124
if (showDebug())
1122-
debug += QString().sprintf("defined at %s:%d<br><br>", _menu->file->name, _menu->lineno);
1125+
stream << "defined at " << _menu->file->name << ":"
1126+
<< _menu->lineno << "<br><br>";
11231127

1124-
setText(head + debug);
1128+
setText(info);
11251129
}
11261130

11271131
QString ConfigInfoView::debug_info(struct symbol *sym)
11281132
{
11291133
QString debug;
1134+
QTextStream stream(&debug);
11301135

1131-
debug += "type: ";
1132-
debug += print_filter(sym_type_name(sym->type));
1136+
stream << "type: ";
1137+
stream << print_filter(sym_type_name(sym->type));
11331138
if (sym_is_choice(sym))
1134-
debug += " (choice)";
1139+
stream << " (choice)";
11351140
debug += "<br>";
11361141
if (sym->rev_dep.expr) {
1137-
debug += "reverse dep: ";
1138-
expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
1139-
debug += "<br>";
1142+
stream << "reverse dep: ";
1143+
expr_print(sym->rev_dep.expr, expr_print_help, &stream, E_NONE);
1144+
stream << "<br>";
11401145
}
11411146
for (struct property *prop = sym->prop; prop; prop = prop->next) {
11421147
switch (prop->type) {
11431148
case P_PROMPT:
11441149
case P_MENU:
1145-
debug += QString().sprintf("prompt: <a href=\"m%s\">", sym->name);
1146-
debug += print_filter(prop->text);
1147-
debug += "</a><br>";
1150+
stream << "prompt: <a href=\"m" << sym->name << "\">";
1151+
stream << print_filter(prop->text);
1152+
stream << "</a><br>";
11481153
break;
11491154
case P_DEFAULT:
11501155
case P_SELECT:
11511156
case P_RANGE:
11521157
case P_COMMENT:
11531158
case P_IMPLY:
11541159
case P_SYMBOL:
1155-
debug += prop_get_type_name(prop->type);
1156-
debug += ": ";
1157-
expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1158-
debug += "<br>";
1160+
stream << prop_get_type_name(prop->type);
1161+
stream << ": ";
1162+
expr_print(prop->expr, expr_print_help,
1163+
&stream, E_NONE);
1164+
stream << "<br>";
11591165
break;
11601166
case P_CHOICE:
11611167
if (sym_is_choice(sym)) {
1162-
debug += "choice: ";
1163-
expr_print(prop->expr, expr_print_help, &debug, E_NONE);
1164-
debug += "<br>";
1168+
stream << "choice: ";
1169+
expr_print(prop->expr, expr_print_help,
1170+
&stream, E_NONE);
1171+
stream << "<br>";
11651172
}
11661173
break;
11671174
default:
1168-
debug += "unknown property: ";
1169-
debug += prop_get_type_name(prop->type);
1170-
debug += "<br>";
1175+
stream << "unknown property: ";
1176+
stream << prop_get_type_name(prop->type);
1177+
stream << "<br>";
11711178
}
11721179
if (prop->visible.expr) {
1173-
debug += "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1174-
expr_print(prop->visible.expr, expr_print_help, &debug, E_NONE);
1175-
debug += "<br>";
1180+
stream << "&nbsp;&nbsp;&nbsp;&nbsp;dep: ";
1181+
expr_print(prop->visible.expr, expr_print_help,
1182+
&stream, E_NONE);
1183+
stream << "<br>";
11761184
}
11771185
}
1178-
debug += "<br>";
1186+
stream << "<br>";
11791187

11801188
return debug;
11811189
}
@@ -1213,15 +1221,15 @@ QString ConfigInfoView::print_filter(const QString &str)
12131221

12141222
void ConfigInfoView::expr_print_help(void *data, struct symbol *sym, const char *str)
12151223
{
1216-
QString* text = reinterpret_cast<QString*>(data);
1217-
QString str2 = print_filter(str);
1224+
QTextStream *stream = reinterpret_cast<QTextStream *>(data);
12181225

12191226
if (sym && sym->name && !(sym->flags & SYMBOL_CONST)) {
1220-
*text += QString().sprintf("<a href=\"s%s\">", sym->name);
1221-
*text += str2;
1222-
*text += "</a>";
1223-
} else
1224-
*text += str2;
1227+
*stream << "<a href=\"s" << sym->name << "\">";
1228+
*stream << print_filter(str);
1229+
*stream << "</a>";
1230+
} else {
1231+
*stream << print_filter(str);
1232+
}
12251233
}
12261234

12271235
void ConfigInfoView::clicked(const QUrl &url)

0 commit comments

Comments
 (0)