Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Created October 31, 2018 22:02
Show Gist options
  • Save stephenquan/9a77e1ccd5d7ea9047a4aae50b25577a to your computer and use it in GitHub Desktop.
Save stephenquan/9a77e1ccd5d7ea9047a4aae50b25577a to your computer and use it in GitHub Desktop.
CertTest.qml
import QtQuick 2.9
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import Qt.Test 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
property NetworkAccessManager manager: NetworkAccessManager
ListModel {
id: encodingFormatListModel
ListElement { code: SslSocket.EncodingFormatDer; txt: "DER" }
ListElement { code: SslSocket.EncodingFormatPem; txt: "PEM" }
}
ListModel {
id: patternSyntaxListModel
ListElement { code: SslSocket.PatternSyntaxWildcard; txt: "Wildcard" }
ListElement { code: SslSocket.PatternSyntaxRegExp; txt: "RegExp" }
ListElement { code: SslSocket.PatternSyntaxRegExp2; txt: "RegExp2" }
ListElement { code: SslSocket.PatternSyntaxFixedString; txt: "FixedString" }
ListElement { code: SslSocket.PatternSyntaxWildcardUnix; txt: "WildcardUnix" }
ListElement { code: SslSocket.PatternSyntaxW3CXmlSchema11; txt: "W3CXmlSchema11" }
}
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
TextField {
id: urlTextField
Layout.fillWidth: true
//text: "https://supt0005934.esri.com/portal/sharing/rest/portals/self?f=pjson"
////text: "https://devtesting.mapsdevext.arcgis.com/sharing/rest/info?f=pjson"
text: "https://supt0005933.esri.com/portal/sharing/rest/portals/self?f=pjson"
wrapMode: TextField.WrapAtWordBoundaryOrAnywhere
}
TextField {
id: certPathTextField
Layout.fillWidth: true
text: Qt.platform.os === "android" ? "/sdcard/certs/*.*" : "/home/squan/certs/*.*"
wrapMode: TextField.WrapAtWordBoundaryOrAnywhere
}
Flow {
Layout.fillWidth: true
spacing: 10
ComboBox {
id: encodingFormatComboBox
Layout.preferredWidth: height * 2
model: encodingFormatListModel
textRole: "txt"
}
ComboBox {
id: patternSyntaxComboBox
model: patternSyntaxListModel
textRole: "txt"
}
Button {
text: qsTr("AddDefaultCaCerts")
onClicked: {
var result = SslSocket.addDefaultCaCertificates(
certPathTextField.text,
encodingFormatListModel.get(encodingFormatComboBox.currentIndex).code,
patternSyntaxListModel.get(patternSyntaxComboBox.currentIndex).code
);
textArea.log("SslSocket.addDefaultCaCertificates: %1".arg(result));
}
}
//}
//RowLayout {
//Layout.fillWidth: true
Button {
text: qsTr("Get")
onClicked: {
textArea.log("NetworkAccessManager.get(%1)".arg(urlTextField.text));
manager.get(urlTextField.text)
}
}
Button {
text: qsTr("ClearAccessCache")
onClicked: {
textArea.log("NetworkAccessManager.clearAccessCache");
manager.clearAccessCache();
}
}
Button {
text: qsTr("Clear")
onClicked: textArea.text = ""
}
}
Flickable {
id: flickable
Layout.fillWidth: true
Layout.fillHeight: true
contentWidth: textArea.width
contentHeight: textArea.height
clip: true
TextArea {
id: textArea
readOnly: true
function log(txt) {
console.log(txt);
text = text + txt + "\n";
}
}
}
}
Connections {
target: manager
onFinished: {
textArea.log("onFinished %1".arg(reply.url));
textArea.log("error: %1".arg(reply.error));
if (reply.error !== 0) {
textArea.log("errorString: %1".arg(reply.errorString));
return;
}
textArea.log("HttpStatusCode: %1".arg(reply.attribute(NetworkReply.NetworkReplyHttpStatusCode)));
textArea.log(reply.readAll());
}
onSslErrors: {
textArea.log("onSslErrors %1".arg(reply.url));
textArea.log(JSON.stringify(errors, undefined, 2));
}
}
Component.onCompleted: {
textArea.log("supportsSsl: %1".arg(SslSocket.supportsSsl));
textArea.log("sslLibraryBuildVersionNumber: %1".arg(SslSocket.sslLibraryBuildVersionNumber));
textArea.log("sslLibraryBuildVersionString: %1".arg(SslSocket.sslLibraryBuildVersionString));
textArea.log("sslLibraryVersionNumber: %1".arg(SslSocket.sslLibraryVersionNumber));
textArea.log("sslLibraryVersionString: %1".arg(SslSocket.sslLibraryVersionString));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment