Important: Please read the Qt Code of Conduct - QSslSocket::connectToHostEncrypted: TLS initialization failed

  • Hello!
    I've written the Fortune Client, which works great. Now, I want to implement the QsslSocket to get an encrypted connection, after the Server answers with welcome, but I do always the error: QSslSocket::connectToHostEncrypted: TLS initialization failed
    This is the code:
    MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , socket(new QSslSocket(this))
    , ui(new Ui::MainWindow)
    qDebug() << QSslSocket::supportsSsl() << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionString();

    tcpSocket = new QTcpSocket(this);
    connect(tcpSocket, &QIODevice::readyRead, this, &MainWindow::readServer);
    connect(tcpSocket, QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error),this, &MainWindow::displayError);


    void MainWindow::messageHandler(QStringList answer){

    if(answer[0] == "welcomeToServer"){
        qDebug()<<"Encryption started";
                 QSslSocket *tsocket = new QSslSocket(this);
                 connect(tsocket, &QIODevice::readyRead, this, &MainWindow::readServer);
                 tsocket->connectToHostEncrypted("", 993);

    hope You can help me

  • I have exactly the same problem and searching for a solution but cant find one !!

  • @Chaki What if you go through this example?

  • Lifetime Qt Champion


    What version of Qt are you using ?
    On what platform ?
    What version of OpenSSL ?
    How did you install everything ?

  • @SGaist
    What do i need to install?

  • Lifetime Qt Champion

    -> OpenSSL
    Check the Maintenance Tool. IIRC, you can install it from there.

  • This post is deleted!

Log in to reply