Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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);
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
48socket->write("1 CAPABILITY\r\n");
50
51
53socket->connectToHostEncrypted("imap", 993);
54if (socket->waitForEncrypted(1000))
55 qDebug("Encrypted!");
57
63
66socket.connectToHostEncrypted("server.tld", 443);
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
Definition qbytearray.h:534
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.
Definition qlist.h:74
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void append(parameter_type t)
Definition qlist.h:441
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
bool waitForReadyRead(int msecs=30000) override
\reimp
void encrypted()
This signal is emitted when QSslSocket enters encrypted mode.
bool waitForEncrypted(int msecs=30000)
Waits until the socket has completed the SSL handshake and has emitted encrypted(),...
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.
void ignoreSslErrors(const QList< QSslError > &errors)
This is an overloaded member function, provided for convenience. It differs from the above function o...
DBusConnection const char DBusError * error
#define qDebug
[1]
Definition qlogging.h:160
ptrdiff_t qintptr
Definition qtypes.h:71
serverDtls doHandshake & serverSocket
QList< QSslError > expectedSslErrors
connect(socket, &QSslSocket::encrypted, this, &Receiver::ready)
QSslSocket * socket
[0]
QList< QSslCertificate > cert
[5]