summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-06-30 09:49:53 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-07-01 14:16:05 +0200
commit331cb9088048154db4338d46cf96b7ff61ad1b5b (patch)
treef3677fd536ce0aeb48211f9e0a9862d3ccad09b7
parentd4ef66065fe82e5f74d668ba4a77500415d188f5 (diff)
Change all QString("foo") constructions to use QStringLiteral
You should not construct QStrings directly from C string literals. Change-Id: I4185376ab62d19c26864afe656e4d7236d20d44c Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.cpp2
-rw-r--r--examples/opcua/waterpump/waterpump-qmlcpp/opcuamachinebackend.cpp7
-rw-r--r--src/imports/opcua/opcuapathresolver.cpp18
-rw-r--r--src/imports/opcua/universalnode.cpp4
-rw-r--r--src/imports/opcua/universalnode.h2
-rw-r--r--tests/auto/clientSetupInCpp/tst_clientSetupInCpp.cpp2
-rw-r--r--tests/auto/connection/tst_connection.cpp4
-rw-r--r--tests/auto/qopcuaclient/tst_client.cpp6
-rw-r--r--tests/auto/security/tst_security.cpp33
-rw-r--r--tests/auto/x509/tst_x509.cpp5
-rw-r--r--tests/manual/gds/tst_gds.cpp5
11 files changed, 55 insertions, 33 deletions
diff --git a/examples/opcua/opcuaviewer/mainwindow.cpp b/examples/opcua/opcuaviewer/mainwindow.cpp
index 6387417..36ba78f 100644
--- a/examples/opcua/opcuaviewer/mainwindow.cpp
+++ b/examples/opcua/opcuaviewer/mainwindow.cpp
@@ -277,7 +277,7 @@ void MainWindow::getEndpointsComplete(const QList<QOpcUaEndpointDescription> &en
continue;
}
- const QString EndpointName = QString("%1 (%2)")
+ const QString EndpointName = QStringLiteral("%1 (%2)")
.arg(endpoint.securityPolicy(), modes[endpoint.securityMode()]);
ui->endpoints->addItem(EndpointName, index++);
}
diff --git a/examples/opcua/waterpump/waterpump-qmlcpp/opcuamachinebackend.cpp b/examples/opcua/waterpump/waterpump-qmlcpp/opcuamachinebackend.cpp
index 3fa46e4..23ce02f 100644
--- a/examples/opcua/waterpump/waterpump-qmlcpp/opcuamachinebackend.cpp
+++ b/examples/opcua/waterpump/waterpump-qmlcpp/opcuamachinebackend.cpp
@@ -127,8 +127,11 @@ void OpcUaMachineBackend::clientStateHandler(QOpcUaClient::ClientState state)
if (state == QOpcUaClient::ClientState::Connecting)
setMessage(QStringLiteral("Connecting"));
- if (state == QOpcUaClient::ClientState::Disconnected)
- setMessage(QString("Disconnected: %1").arg(QMetaEnum::fromType<QOpcUaClient::ClientError>().valueToKey(static_cast<int>(m_client->error()))));
+ if (state == QOpcUaClient::ClientState::Disconnected) {
+ setMessage(QStringLiteral("Disconnected: %1")
+ .arg(QMetaEnum::fromType<QOpcUaClient::ClientError>().valueToKey(
+ static_cast<int>(m_client->error()))));
+ }
}
void OpcUaMachineBackend::machineStateUpdated(QOpcUa::NodeAttribute attr, const QVariant &value)
diff --git a/src/imports/opcua/opcuapathresolver.cpp b/src/imports/opcua/opcuapathresolver.cpp
index 5ec0076..95b09e9 100644
--- a/src/imports/opcua/opcuapathresolver.cpp
+++ b/src/imports/opcua/opcuapathresolver.cpp
@@ -147,7 +147,8 @@ void OpcUaPathResolver::startNodeResolved(UniversalNode startNode, const QString
startNode.resolveNamespace(m_client);
m_node = m_client->node(startNode.fullNodeId());
if (!m_node) {
- emit resolvedNode(startNode, QString("Could not create node from '%1'").arg(startNode.fullNodeId()));
+ emit resolvedNode(startNode, QStringLiteral("Could not create node from '%1'")
+ .arg(startNode.fullNodeId()));
deleteLater();
return;
}
@@ -160,7 +161,7 @@ void OpcUaPathResolver::startNodeResolved(UniversalNode startNode, const QString
qCDebug(QT_OPCUA_PLUGINS_QML) << "Starting browse on" << m_node->nodeId();
connect(m_node, &QOpcUaNode::resolveBrowsePathFinished, this, &OpcUaPathResolver::browsePathFinished);
if (!m_node->resolveBrowsePath(path)) {
- emit resolvedNode(UniversalNode(), QString("Failed to start browse"));
+ emit resolvedNode(UniversalNode(), QStringLiteral("Failed to start browse"));
deleteLater();
return;
}
@@ -173,18 +174,22 @@ void OpcUaPathResolver::browsePathFinished(QList<QOpcUaBrowsePathTarget> results
if (status != QOpcUa::Good) {
const char *name = QMetaEnum::fromType<QOpcUa::UaStatusCode>().valueToKey(status);
- emit resolvedNode(UniversalNode(), QString("Resolving browse path return error code %1").arg(name));
+ emit resolvedNode(UniversalNode(),
+ QStringLiteral("Resolving browse path return error code %1").arg(name));
deleteLater();
return;
}
if (results.size() == 0) {
- emit resolvedNode(UniversalNode(), QString("Relative path could not be resolved: Results are empty"));
+ emit resolvedNode(UniversalNode(),
+ QStringLiteral("Relative path could not be resolved: Results are empty"));
deleteLater();
return;
} else if (results.size() == 1) {
if (results.at(0).targetId().serverIndex() > 0) {
- emit resolvedNode(UniversalNode(), QString("Relative path could not be resolved: Resulting node is located on a remote server"));
+ emit resolvedNode(UniversalNode(),
+ QStringLiteral("Relative path could not be resolved: "
+ "Resulting node is located on a remote server"));
deleteLater();
return;
}
@@ -197,7 +202,8 @@ void OpcUaPathResolver::browsePathFinished(QList<QOpcUaBrowsePathTarget> results
for (const auto &result : results) {
if (result.isFullyResolved()) {
if (result.targetId().serverIndex() > 0) {
- message = QString("Relative path could not be resolved: Resulting node is located on a remote server");
+ message = QStringLiteral("Relative path could not be resolved: "
+ "Resulting node is located on a remote server");
continue;
}
if (!tmp.nodeIdentifier().isEmpty()) {
diff --git a/src/imports/opcua/universalnode.cpp b/src/imports/opcua/universalnode.cpp
index 90697f4..5531a2c 100644
--- a/src/imports/opcua/universalnode.cpp
+++ b/src/imports/opcua/universalnode.cpp
@@ -163,7 +163,9 @@ void UniversalNode::resolveNamespaceNameToIndex(QOpcUaClient *client)
int index = resolveNamespaceNameToIndex(m_namespaceName, client);
if (index < 0) {
- qCWarning(QT_OPCUA_PLUGINS_QML) << "Could not resolve namespace for node" << (m_nodeIdentifier.isEmpty() ? QString() : (QString("(") + m_nodeIdentifier + ")"));
+ qCWarning(QT_OPCUA_PLUGINS_QML)
+ << "Could not resolve namespace for node"
+ << (m_nodeIdentifier.isEmpty() ? QString() : (u'(' + m_nodeIdentifier + u')'));
return;
}
setMembers(true, index, true, m_namespaceName, false, QString());
diff --git a/src/imports/opcua/universalnode.h b/src/imports/opcua/universalnode.h
index 4772600..bf12ed4 100644
--- a/src/imports/opcua/universalnode.h
+++ b/src/imports/opcua/universalnode.h
@@ -97,7 +97,7 @@ public:
static QString resolveNamespaceToNode(const QString &nodeId, const QString &namespaceName, QOpcUaClient *client);
inline static QString createNodeString(int namespaceIndex, const QString &nodeIdentifier) {
- return QString("ns=%1;%2").arg(namespaceIndex).arg(nodeIdentifier);
+ return QStringLiteral("ns=%1;%2").arg(namespaceIndex).arg(nodeIdentifier);
}
static bool splitNodeIdAndNamespace(const QString nodeIdentifier, int *namespaceIndex, QString *identifier);
diff --git a/tests/auto/clientSetupInCpp/tst_clientSetupInCpp.cpp b/tests/auto/clientSetupInCpp/tst_clientSetupInCpp.cpp
index 99f3871..0c86b9c 100644
--- a/tests/auto/clientSetupInCpp/tst_clientSetupInCpp.cpp
+++ b/tests/auto/clientSetupInCpp/tst_clientSetupInCpp.cpp
@@ -83,7 +83,7 @@ public slots:
QString host = envOrDefault("OPCUA_HOST", defaultHost.toString());
QString port = envOrDefault("OPCUA_PORT", QString::number(defaultPort));
- const auto discoveryEndpoint = QString("opc.tcp://%1:%2").arg(host).arg(port);
+ const auto discoveryEndpoint = QStringLiteral("opc.tcp://%1:%2").arg(host).arg(port);
QSignalSpy endpointSpy(client, &QOpcUaClient::endpointsRequestFinished);
client->requestEndpoints(discoveryEndpoint);
diff --git a/tests/auto/connection/tst_connection.cpp b/tests/auto/connection/tst_connection.cpp
index 4fa884f..185ebd2 100644
--- a/tests/auto/connection/tst_connection.cpp
+++ b/tests/auto/connection/tst_connection.cpp
@@ -105,7 +105,7 @@ void Tst_Connection::initTestCase()
QOpcUaClient *client = m_opcUa.createClient(backend, backendOptions);
QVERIFY2(client != nullptr,
- QString("Loading backend failed: %1").arg(backend).toLatin1().data());
+ QStringLiteral("Loading backend failed: %1").arg(backend).toLatin1().data());
client->setParent(this);
qDebug() << "Using SDK plugin:" << client->backend();
m_clients.append(client);
@@ -155,7 +155,7 @@ void Tst_Connection::initTestCase()
}
QString host = envOrDefault("OPCUA_HOST", defaultHost.toString());
QString port = envOrDefault("OPCUA_PORT", QString::number(defaultPort));
- m_discoveryEndpoint = QString("opc.tcp://%1:%2").arg(host).arg(port);
+ m_discoveryEndpoint = QStringLiteral("opc.tcp://%1:%2").arg(host).arg(port);
qDebug() << "Using endpoint:" << m_discoveryEndpoint;
QOpcUaClient *client = m_clients.first();
diff --git a/tests/auto/qopcuaclient/tst_client.cpp b/tests/auto/qopcuaclient/tst_client.cpp
index d246fc5..18c4f65 100644
--- a/tests/auto/qopcuaclient/tst_client.cpp
+++ b/tests/auto/qopcuaclient/tst_client.cpp
@@ -561,7 +561,7 @@ void Tst_QOpcUaClient::initTestCase()
QOpcUaClient *client = m_opcUa.createClient(backend, backendOptions);
QVERIFY2(client != nullptr,
- QString("Loading backend failed: %1").arg(backend).toLatin1().data());
+ QStringLiteral("Loading backend failed: %1").arg(backend).toLatin1().data());
client->setParent(this);
qDebug() << "Using SDK plugin:" << client->backend();
m_clients.append(client);
@@ -625,7 +625,7 @@ void Tst_QOpcUaClient::initTestCase()
}
QString host = envOrDefault("OPCUA_HOST", defaultHost.toString());
QString port = envOrDefault("OPCUA_PORT", QString::number(defaultPort));
- m_discoveryEndpoint = QString("opc.tcp://%1:%2").arg(host).arg(port);
+ m_discoveryEndpoint = QStringLiteral("opc.tcp://%1:%2").arg(host).arg(port);
qDebug() << "Using endpoint:" << m_discoveryEndpoint;
QOpcUaClient *client = m_clients.first();
@@ -3716,7 +3716,7 @@ void Tst_QOpcUaClient::addNamespace()
QCOMPARE(namespaceChangedSpy.count(), 0);
auto namespaceArray = opcuaClient->namespaceArray();
- QString newNamespaceName = QString("DynamicTestNamespace#%1").arg(namespaceArray.size());
+ QString newNamespaceName = QStringLiteral("DynamicTestNamespace#%1").arg(namespaceArray.size());
QVERIFY(!namespaceArray.isEmpty());
QVERIFY(!namespaceArray.contains(newNamespaceName));
diff --git a/tests/auto/security/tst_security.cpp b/tests/auto/security/tst_security.cpp
index 70450ed..208a176 100644
--- a/tests/auto/security/tst_security.cpp
+++ b/tests/auto/security/tst_security.cpp
@@ -131,7 +131,10 @@ static QString messageSecurityModeToString(QOpcUaEndpointDescription::MessageSec
QTest::addColumn<QOpcUaEndpointDescription>("endpoint");\
for (auto backend : m_backends)\
for (auto endpoint : m_endpoints) { \
- const QString rowName = QString("%1 using %2 %3").arg(backend).arg(endpoint.securityPolicy()).arg(messageSecurityModeToString(endpoint.securityMode())); \
+ const QString rowName = QStringLiteral("%1 using %2 %3") \
+ .arg(backend) \
+ .arg(endpoint.securityPolicy()) \
+ .arg(messageSecurityModeToString(endpoint.securityMode())); \
QTest::newRow(rowName.toLatin1().constData()) << backend << endpoint; \
} \
}
@@ -225,7 +228,7 @@ void Tst_QOpcUaSecurity::initTestCase()
}
QString host = envOrDefault("OPCUA_HOST", defaultHost.toString());
QString port = envOrDefault("OPCUA_PORT", QString::number(defaultPort));
- m_discoveryEndpoint = QString("opc.tcp://%1:%2").arg(host).arg(port);
+ m_discoveryEndpoint = QStringLiteral("opc.tcp://%1:%2").arg(host).arg(port);
qDebug() << "Using endpoint:" << m_discoveryEndpoint;
QScopedPointer<QOpcUaClient> client(m_opcUa.createClient(m_backends.first()));
@@ -263,11 +266,13 @@ void Tst_QOpcUaSecurity::connectAndDisconnectSecureUnencryptedKey()
QFETCH(QOpcUaEndpointDescription, endpoint);
QScopedPointer<QOpcUaClient> client(m_opcUa.createClient(backend));
- QVERIFY2(client, QString("Loading backend failed: %1").arg(backend).toLatin1().data());
+ QVERIFY2(client, QStringLiteral("Loading backend failed: %1").arg(backend).toLatin1().data());
- if (!client->supportedSecurityPolicies().contains(endpoint.securityPolicy()))
- QSKIP(QString("This test is skipped because backend %1 does not support security policy %2").arg(
- client->backend()).arg(endpoint.securityPolicy()).toLatin1().constData());
+ if (!client->supportedSecurityPolicies().contains(endpoint.securityPolicy())) {
+ QSKIP(QStringLiteral("This test is skipped because backend %1 "
+ "does not support security policy %2")
+ .arg(client->backend()).arg(endpoint.securityPolicy()).toLatin1().constData());
+ }
const QString pkidir = m_pkiData->path();
QOpcUaPkiConfiguration pkiConfig;
@@ -329,13 +334,19 @@ void Tst_QOpcUaSecurity::connectAndDisconnectSecureEncryptedKey()
QFETCH(QOpcUaEndpointDescription, endpoint);
QScopedPointer<QOpcUaClient> client(m_opcUa.createClient(backend));
- QVERIFY2(client, QString("Loading backend failed: %1").arg(backend).toLatin1().data());
+ QVERIFY2(client, QStringLiteral("Loading backend failed: %1").arg(backend).toLatin1().data());
- if (client->backend() == QLatin1String("open62541"))
- QSKIP(QString("This test is skipped because backend %1 does not support encrypted keys").arg(client->backend()).toLatin1().constData());
+ if (client->backend() == QLatin1String("open62541")) {
+ QSKIP(QStringLiteral("This test is skipped because backend %1 "
+ "does not support encrypted keys")
+ .arg(client->backend()).toLatin1().constData());
+ }
- if (!client->supportedSecurityPolicies().contains(endpoint.securityPolicy()))
- QSKIP(QString("This test is skipped because backend %1 does not support security policy %2").arg(client->backend()).arg(endpoint.securityPolicy()).toLatin1().constData());
+ if (!client->supportedSecurityPolicies().contains(endpoint.securityPolicy())) {
+ QSKIP(QStringLiteral("This test is skipped because backend %1 "
+ "does not support security policy %2")
+ .arg(client->backend()).arg(endpoint.securityPolicy()).toLatin1().constData());
+ }
const QString pkidir = m_pkiData->path();
QOpcUaPkiConfiguration pkiConfig;
diff --git a/tests/auto/x509/tst_x509.cpp b/tests/auto/x509/tst_x509.cpp
index d00c3d9..6f27377 100644
--- a/tests/auto/x509/tst_x509.cpp
+++ b/tests/auto/x509/tst_x509.cpp
@@ -52,7 +52,7 @@
{\
QTest::addColumn<QString>("backend");\
for (auto backend : m_backends) {\
- const QString rowName = QString("%1").arg(backend); \
+ const QString rowName = QStringLiteral("%1").arg(backend); \
QTest::newRow(rowName.toLatin1().constData()) << backend ; \
}\
}
@@ -158,7 +158,8 @@ void Tst_QOpcUaSecurity::keyPairs()
QCOMPARE(loadedKey.privateKeyToByteArray(QOpcUaKeyPair::Cipher::Unencrypted, QString()), byteArray);
// Check encrypted PEM export
- byteArray = key.privateKeyToByteArray(QOpcUaKeyPair::Cipher::Aes128Cbc, QString("password"));
+ byteArray = key.privateKeyToByteArray(QOpcUaKeyPair::Cipher::Aes128Cbc,
+ QStringLiteral("password"));
QVERIFY(byteArray.startsWith("-----BEGIN ENCRYPTED PRIVATE KEY-----\n"));
QVERIFY(byteArray.endsWith("-----END ENCRYPTED PRIVATE KEY-----\n"));
QCOMPARE(passwordSpy.count(), 0);
diff --git a/tests/manual/gds/tst_gds.cpp b/tests/manual/gds/tst_gds.cpp
index c0ece32..8eb7d49 100644
--- a/tests/manual/gds/tst_gds.cpp
+++ b/tests/manual/gds/tst_gds.cpp
@@ -54,9 +54,8 @@
#define defineDataMethod(name) void name()\
{\
QTest::addColumn<QString>("backend");\
- for (auto backend : m_backends) {\
- const QString rowName = QString("%1").arg(backend); \
- QTest::newRow(rowName.toLatin1().constData()) << backend ; \
+ for (const QString &backend : m_backends) {\
+ QTest::newRow(backend.toLatin1().constData()) << backend ; \
QVERIFY(!backend.isEmpty()); \
}\
}