Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Sample QSslSocket Example

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Emulator / desktop / device
Platform(s): All Qt Supported
Keywords: QSslSocket
Created: skumar_rao (26 Nov 2010)
Last edited: hamishwillee (11 Oct 2012)


The QSslSocket class provides an SSL encrypted socket for both clients and servers.QSslSocket establishes a secure, encrypted TCP connection you can use for transmitting encrypted data. It can operate in both client and server mode, and it supports modern SSL protocols.

SSL encryption operates on top of the existing TCP stream after the socket enters the ConnectedState. There are two simple ways to establish a secure connection using QSslSocket: With an immediate SSL handshake, or with a delayed SSL handshake occurring after the connection has been established in unencrypted mode. The most common way to use QSslSocket is to construct an object and start a secure connection by calling connectToHostEncrypted(). This method starts an immediate SSL handshake once the connection has been established.

#include <QApplication>
#include <QSslSocket>
#include <QDebug>
int main( int argc, char **argv )
QApplication app( argc, argv );
QSslSocket socket;
socket.connectToHostEncrypted( "", 443 );
if ( !socket.waitForEncrypted() ) {
qDebug() << socket.errorString();
return 1;
socket.write( "GET / HTTP/1.1\r\n" \
"Host:\r\n" \
"Connection: Close\r\n\r\n" );
while ( socket.waitForReadyRead() ) {
qDebug() << socket.readAll().data();
qDebug() << "Done";
return 0;

More information you can find in

--skumar_rao 19:19, 26 November 2010 (UTC)

This page was last modified on 11 October 2012, at 01:18.
151 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.