diff options
author | Marc Mutz <[email protected]> | 2024-05-22 14:56:26 +0200 |
---|---|---|
committer | Ahmad Samir <[email protected]> | 2024-12-03 23:45:55 +0200 |
commit | 6212c32f1fa5e86a808713f33b331f2dad113e99 (patch) | |
tree | a5cb754822b727b7be6f4c9e258a2ab2be9c0fc4 | |
parent | f7e8e54d7e6803c91cc453afdfc46f3d0b4da9c2 (diff) |
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 <[email protected]>
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 10 | ||||
-rw-r--r-- | src/network/access/qdecompresshelper.cpp | 3 | ||||
-rw-r--r-- | src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 2 | ||||
-rw-r--r-- | src/plugins/tls/openssl/qsslcontext_openssl.cpp | 13 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 3 | ||||
-rw-r--r-- | src/tools/rcc/rcc.cpp | 4 | ||||
-rw-r--r-- | src/tools/uic/cpp/cppwriteinitialization.cpp | 4 |
7 files changed, 19 insertions, 20 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 2aacc4cc50d..c7412b6a7da 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -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 diff --git a/src/network/access/qdecompresshelper.cpp b/src/network/access/qdecompresshelper.cpp index 764c0260c06..e2fd2a946cf 100644 --- a/src/network/access/qdecompresshelper.cpp +++ b/src/network/access/qdecompresshelper.cpp @@ -20,6 +20,9 @@ #include <array> QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + namespace { struct ContentEncodingMapping { diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index 6b1a1c28f14..7e04a20da5b 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -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); diff --git a/src/plugins/tls/openssl/qsslcontext_openssl.cpp b/src/plugins/tls/openssl/qsslcontext_openssl.cpp index 75c192bd01d..4e141682d5b 100644 --- a/src/plugins/tls/openssl/qsslcontext_openssl.cpp +++ b/src/plugins/tls/openssl/qsslcontext_openssl.cpp @@ -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; } } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 4caa4dab6a7..8b7f7479751 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -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; diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 563672243b3..03093b11ecb 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -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") diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp index 34d882f110d..5600c549bf7 100644 --- a/src/tools/uic/cpp/cppwriteinitialization.cpp +++ b/src/tools/uic/cpp/cppwriteinitialization.cpp @@ -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; |