Replace a few toString() or fromUtf8() QString::arg() parameters

...and fromUtf8() format strings.

QString::arg() is now available on QUtf8StringView, too and can handle
UTF-8 arguments directly.

Change-Id: Ifa8b1ea0f41414d15a6919b1967e0a45e4d7929f
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
Marc Mutz 2024-05-22 14:56:26 +02:00 committed by Ahmad Samir
parent f7e8e54d7e
commit 6212c32f1f
7 changed files with 19 additions and 20 deletions

View File

@ -789,18 +789,18 @@ static QString startFailureErrorMessage(ChildError &err, [[maybe_unused]] ssize_
Q_ASSERT(bytesRead == sizeof(err));
qsizetype len = qstrnlen(err.function, sizeof(err.function));
QString complement = QString::fromUtf8(err.function, len);
const QUtf8StringView complement(err.function, len);
if (err.code == FakeErrnoForThrow)
return QProcess::tr("Child process modifier threw an exception: %1")
.arg(std::move(complement));
.arg(complement);
if (err.code == 0)
return QProcess::tr("Child process modifier reported error: %1")
.arg(std::move(complement));
.arg(complement);
if (err.code < 0)
return QProcess::tr("Child process modifier reported error: %1: %2")
.arg(std::move(complement), qt_error_string(-err.code));
.arg(complement, qt_error_string(-err.code));
return QProcess::tr("Child process set up failed: %1: %2")
.arg(std::move(complement), qt_error_string(err.code));
.arg(complement, qt_error_string(err.code));
}
Q_NORETURN void

View File

@ -20,6 +20,9 @@
#include <array>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace {
struct ContentEncodingMapping
{

View File

@ -1519,7 +1519,7 @@ QSqlRecord QMYSQLDriver::record(const QString &tablename) const
const auto len = mysql_real_escape_string_quote(d->mysql, tableNameQuoted.data(),
baTableName.data(), baTableName.size(), '\'');
#endif
if (i.exec(stmt.arg(QString::fromUtf8(tableNameQuoted.data(), len)))) {
if (i.exec(stmt.arg(QUtf8StringView(tableNameQuoted.data(), len)))) {
while (i.next()) {
const auto colName = i.value(0).toString();
const auto recordIdx = r.indexOf(colName);

View File

@ -772,8 +772,7 @@ void QSslContext::applyBackendConfig(QSslContext *sslContext)
if (!i.value().canConvert(QMetaType(QMetaType::QByteArray))) {
sslContext->errorCode = QSslError::UnspecifiedError;
sslContext->errorStr = msgErrorSettingBackendConfig(
QSslSocket::tr("Expecting QByteArray for %1").arg(
QString::fromUtf8(i.key())));
QSslSocket::tr("Expecting QByteArray for %1").arg(i.key()));
return;
}
@ -786,18 +785,16 @@ void QSslContext::applyBackendConfig(QSslContext *sslContext)
switch (result) {
case 0:
sslContext->errorStr = msgErrorSettingBackendConfig(
QSslSocket::tr("An error occurred attempting to set %1 to %2").arg(
QString::fromUtf8(i.key()), QString::fromUtf8(value)));
QSslSocket::tr("An error occurred attempting to set %1 to %2")
.arg(i.key(), value));
return;
case 1:
sslContext->errorStr = msgErrorSettingBackendConfig(
QSslSocket::tr("Wrong value for %1 (%2)").arg(
QString::fromUtf8(i.key()), QString::fromUtf8(value)));
QSslSocket::tr("Wrong value for %1 (%2)").arg(i.key(), value));
return;
default:
sslContext->errorStr = msgErrorSettingBackendConfig(
QSslSocket::tr("Unrecognized command %1 = %2").arg(
QString::fromUtf8(i.key()), QString::fromUtf8(value)));
QSslSocket::tr("Unrecognized command %1 = %2").arg(i.key(), value));
return;
}
}

View File

@ -346,8 +346,7 @@ QString Internal::formatTryTimeoutDebugMessage(q_no_char8_t::QUtf8StringView exp
{
return "QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) "
"was too short, %3 ms would have been sufficient this time."_L1
// ### Qt 7: remove the toString() (or earlier, when arg() can handle QUtf8StringView), passing the view directly
.arg(expr.toString(), QString::number(timeout), QString::number(actual));
.arg(expr, QString::number(timeout), QString::number(actual));
}
extern Q_TESTLIB_EXPORT int lastMouseTimestamp;

View File

@ -325,8 +325,8 @@ qint64 RCCFileInfo::writeDataBlob(RCCResourceLibrary &lib,
CONSTANT_ZSTDCOMPRESSLEVEL_STORE);
}
if (ZSTD_isError(n)) {
QString msg = QString::fromLatin1("%1: error: compression with zstd failed: %2\n")
.arg(m_name, QString::fromUtf8(ZSTD_getErrorName(n)));
QString msg = "%1: error: compression with zstd failed: %2\n"_L1
.arg(m_name, ZSTD_getErrorName(n));
lib.m_errorDevice->write(msg.toUtf8());
} else if (lib.verbose()) {
QString msg = QString::fromLatin1("%1: note: compressed using zstd (%2 -> %3)\n")

View File

@ -237,7 +237,7 @@ namespace {
if (const DomResourceIcon *dri = p->elementIconSet()) {
if (!isIconFormat44(dri)) {
if (dri->text().isEmpty()) {
const QString msg = QString::fromLatin1("%1: Warning: An invalid icon property '%2' was encountered.")
const QString msg = "%1: Warning: An invalid icon property '%2' was encountered."_L1
.arg(fileName, name);
qWarning("%s", qPrintable(msg));
return false;
@ -248,7 +248,7 @@ namespace {
case DomProperty::Pixmap:
if (const DomResourcePixmap *drp = p->elementPixmap())
if (drp->text().isEmpty()) {
const QString msg = QString::fromUtf8("%1: Warning: An invalid pixmap property '%2' was encountered.")
const QString msg = "%1: Warning: An invalid pixmap property '%2' was encountered."_L1
.arg(fileName, name);
qWarning("%s", qPrintable(msg));
return false;