diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-06-16 17:14:41 +0200 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2023-06-22 10:58:45 +0200 |
commit | 967163e3d8fd31e2da77122023bd97ed0880484b (patch) | |
tree | 5da17438f09c17187a5ad63be856fc6cfba1afc4 | |
parent | 313426f097308312ce735b10ac2bb01bc47105ea (diff) |
Secure CoAP Client: fix qmllint warnings
These were mostly unqualified access warnings, which were fixed by
explicitly specifying the id.
Also replace injection of a context propertly with setting the initial
properties for the engine. This allows to declare 'hostsModel' as a
required property in the Main.qml
Another common warning is M325 "Logical value does not depend
on actual values". It is fixed by explicitly casting
securityModelGroup.checkedButton to RadioButton.
Task-number: QTBUG-113858
Pick-to: 6.6 6.5
Change-Id: Ic334122892510b6bbd5e06ac9d00d99893b7e46c
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
-rw-r--r-- | examples/coap/quicksecureclient/FilePicker.qml | 6 | ||||
-rw-r--r-- | examples/coap/quicksecureclient/Main.qml | 20 | ||||
-rw-r--r-- | examples/coap/quicksecureclient/main.cpp | 4 |
3 files changed, 18 insertions, 12 deletions
diff --git a/examples/coap/quicksecureclient/FilePicker.qml b/examples/coap/quicksecureclient/FilePicker.qml index 557a64e..cc24464 100644 --- a/examples/coap/quicksecureclient/FilePicker.qml +++ b/examples/coap/quicksecureclient/FilePicker.qml @@ -17,7 +17,7 @@ Item { FileDialog { id: fileDialog - title: qsTr("Please Choose %1").arg(dialogText) + title: qsTr("Please Choose %1").arg(filePicker.dialogText) currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation) fileMode: FileDialog.OpenFile onAccepted: filePathField.text = fileDialog.selectedFile @@ -27,7 +27,7 @@ Item { anchors.fill: parent TextField { id: filePathField - placeholderText: qsTr("<%1>").arg(dialogText) + placeholderText: qsTr("<%1>").arg(filePicker.dialogText) inputMethodHints: Qt.ImhUrlCharactersOnly selectByMouse: true Layout.fillWidth: true @@ -35,7 +35,7 @@ Item { Button { id: addFileButton - text: qsTr("Add %1").arg(dialogText) + text: qsTr("Add %1").arg(filePicker.dialogText) onClicked: fileDialog.open() } } diff --git a/examples/coap/quicksecureclient/Main.qml b/examples/coap/quicksecureclient/Main.qml index c7cb977..9762f5c 100644 --- a/examples/coap/quicksecureclient/Main.qml +++ b/examples/coap/quicksecureclient/Main.qml @@ -7,6 +7,10 @@ import QtQuick.Controls import QtQuick.Window Window { + id: root + + required property var hostsModel + visible: true width: 480 height: 640 @@ -14,7 +18,7 @@ Window { CoapSecureClient { id: client - onFinished: { + onFinished: (result) => { outputView.text = result; statusLabel.text = ""; disconnectButton.enabled = true; @@ -32,7 +36,7 @@ Window { ComboBox { id: hostComboBox editable: true - model: hostsModel + model: root.hostsModel Layout.fillWidth: true } @@ -64,7 +68,7 @@ Window { ButtonGroup { id: securityModeGroup onClicked: { - if (securityModeGroup.checkedButton === preSharedMode) + if ((securityModeGroup.checkedButton as RadioButton) === preSharedMode) client.setSecurityMode(QtCoap.SecurityMode.PreSharedKey); else client.setSecurityMode(QtCoap.SecurityMode.Certificate); @@ -84,7 +88,7 @@ Window { } RowLayout { - enabled: securityModeGroup.checkedButton === preSharedMode + enabled: (securityModeGroup.checkedButton as RadioButton) === preSharedMode Layout.columnSpan: 2 Label { @@ -109,7 +113,7 @@ Window { FilePicker { id: localCertificatePicker dialogText: qsTr("Local Certificate") - enabled: securityModeGroup.checkedButton === certificateMode + enabled: (securityModeGroup.checkedButton as RadioButton) === certificateMode Layout.columnSpan: 2 Layout.fillWidth: true } @@ -117,7 +121,7 @@ Window { FilePicker { id: caCertificatePicker dialogText: qsTr("CA Certificate") - enabled: securityModeGroup.checkedButton === certificateMode + enabled: (securityModeGroup.checkedButton as RadioButton) === certificateMode Layout.columnSpan: 2 Layout.fillWidth: true } @@ -125,7 +129,7 @@ Window { FilePicker { id: privateKeyPicker dialogText: qsTr("Private Key") - enabled: securityModeGroup.checkedButton === certificateMode + enabled: (securityModeGroup.checkedButton as RadioButton) === certificateMode Layout.columnSpan: 2 Layout.fillWidth: true } @@ -137,7 +141,7 @@ Window { onClicked: { outputView.text = ""; - if (securityModeGroup.checkedButton === preSharedMode) + if ((securityModeGroup.checkedButton as RadioButton) === preSharedMode) client.setSecurityConfiguration(pskField.text, identityField.text); else client.setSecurityConfiguration(localCertificatePicker.selectedFile, diff --git a/examples/coap/quicksecureclient/main.cpp b/examples/coap/quicksecureclient/main.cpp index ec36e83..dfef85d 100644 --- a/examples/coap/quicksecureclient/main.cpp +++ b/examples/coap/quicksecureclient/main.cpp @@ -6,6 +6,8 @@ #include <QQmlApplicationEngine> #include <QQmlContext> +using namespace Qt::StringLiterals; + static QStringList availableHosts() { QStringList hosts; @@ -22,7 +24,7 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - engine.rootContext()->setContextProperty("hostsModel", availableHosts()); + engine.setInitialProperties({{u"hostsModel"_s, availableHosts()}}); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(1); }, |