Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_network_ssl_qsslsocket.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4using namespace Qt::StringLiterals;
5
8connect(socket, &QSslSocket::encrypted, this, &Receiver::ready);
9
10socket->connectToHostEncrypted("imap.example.com", 993);
12
13
15void SslServer::incomingConnection(qintptr socketDescriptor)
16{
18 if (serverSocket->setSocketDescriptor(socketDescriptor)) {
19 addPendingConnection(serverSocket);
20 connect(serverSocket, &QSslSocket::encrypted, this, &SslServer::ready);
21 serverSocket->startServerEncryption();
22 } else {
23 delete serverSocket;
24 }
25}
27
28
31socket.connectToHostEncrypted("http.example.com", 443);
32if (!socket.waitForEncrypted()) {
34 return false;
35}
36
37socket.write("GET / HTTP/1.0\r\n\r\n");
39 qDebug() << socket.readAll().data();
41
42
45connect(&socket, &QSslSocket::encrypted, receiver, &Receiver::socketEncrypted);
46
47socket.connectToHostEncrypted("imap", 993);
48socket->write("1 CAPABILITY\r\n");
50
51
53socket->connectToHostEncrypted("imap", 993);
54if (socket->waitForEncrypted(1000))
55 qDebug("Encrypted!");
57
59QList<QSslCertificate> cert = QSslCertificate::fromPath("server-certificate.pem"_L1);
61QList<QSslError> expectedSslErrors;
63
65socket.ignoreSslErrors(expectedSslErrors);
66socket.connectToHostEncrypted("server.tld", 443);
bool waitForReadyRead(int msecs=30000) override
This function blocks until new data is available for reading and the \l{QIODevice::}{readyRead()} sig...
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:611
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void append(parameter_type t)
Definition qlist.h:458
static QList< QSslCertificate > fromPath(const QString &path, QSsl::EncodingFormat format=QSsl::Pem, PatternSyntax syntax=PatternSyntax::FixedString)
The QSslError class provides an SSL error.
Definition qsslerror.h:21
@ SelfSignedCertificate
Definition qsslerror.h:34
The QSslSocket class provides an SSL encrypted socket for both clients and servers.
Definition qsslsocket.h:29
void encrypted()
This signal is emitted when QSslSocket enters encrypted mode.
void connectToHostEncrypted(const QString &hostName, quint16 port, OpenMode mode=ReadWrite, NetworkLayerProtocol protocol=AnyIPProtocol)
Starts an encrypted connection to the device hostName on port, using mode as the \l OpenMode.
DBusConnection const char DBusError * error
#define qDebug
[1]
Definition qlogging.h:164
ptrdiff_t qintptr
Definition qtypes.h:166
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QTcpSocket * socket
[1]
QList< QSslError > expectedSslErrors
QList< QSslCertificate > cert
[0]
serverDtls doHandshake & serverSocket
connect(socket, &QSslSocket::encrypted, this, &Receiver::ready)
QSslSocket * socket
[0]