Why does it show me this warning?
Unsolved
General and Desktop
-
Hi guys, I have the following code:
In My .hpp
void setLabelInfo(const QString &color, const QString& userName="PUBLIC") noexcept;
The .cpp
void Widget::setLabelInfo(const QString& color, const QString& userName) noexcept { ui->lblInfo->setText(QString("<span style='color:%1;'>" "<strong>MyCompany - Super User " "</strong></span>").arg(color)); ui->lblState->setText(QString("<span style='color:%1;'>" "<strong>User: %2" "</strong></span>").arg(color).arg(userName)); }
I get this warning, here I leave the image, why does that message appear, and how can I improve it, thanks in advance.
I am using Qt 6.2.4 and Clang compiler 16.0.5
-
-
@Christian-Ehrlicher that warning
-
@Lincoln you're supposed to use this arg overload
https://doc.qt.io/qt-6/qstring.html#arg-14
which is one call, currently you're calling arg(arg) and on the temporary you call again arg(arg) with the 2nd argument
ui->lblState->setText(QString("<span style='color:%1;'>"
"<strong>User: %2"
"</strong></span>").arg(color, userName));Assuming color and userName are QStrings or implicitly converted. Also use QStringLiteral here instead of QString, its "cleaner"