添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Welcome to Qt Centre .

Qt Centre is a community site devoted to programming in C++ using the Qt framework . Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue — register and post your question.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today !

If you have any problems with the registration process or your account login, please contact us .

  1. //H
  2.  
  3. #ifndef POLACZENIESSL_H
  4. #define POLACZENIESSL_H
  5. #include <QTcpServer>
  6. #include <QTcpSocket>
  7. #include <QSslSocket>
  8. #include <QFile>
  9. #include <QSslKey>
  10. #include <QAbstractSocket>
  11. class PolaczenieSSL : public QTcpServer
  12. {
  13. Q_OBJECT
  14. public:
  15. PolaczenieSSL(QWidget *parent = 0);
  16. ~PolaczenieSSL();
  17. private:
  18. void incomingConnection(int port);
  19. private slots:
  20. void gotowy();
  21. };
  22.  
  23. #endif // POLACZENIESSL_H
  24.  
  25. //CPP
  26.  
  27. #include "polaczeniessl.h"
  28.  
  29. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
  30. {
  31.  
  32. }
  33. PolaczenieSSL::~PolaczenieSSL()
  34. {
  35.  
  36. }
  37. void PolaczenieSSL::incomingConnection(int port)
  38. {
  39. qDebug()<<"incomingConnection";
  40. QSslSocket *serverSocket = new QSslSocket;
  41. serverSocket->setProtocol(QSsl::AnyProtocol);
  42. serverSocket->ignoreSslErrors();
  43. QFile *file = new QFile("server.key");
  44. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
  45. serverSocket->setPrivateKey(key);
  46. serverSocket->setLocalCertificate("server.csr");
  47. serverSocket->addCaCertificates("/etc/ssl/certs");
  48. if (serverSocket->setSocketDescriptor(port))
  49. {
  50. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
  51. serverSocket->startServerEncryption();
  52. qDebug()<<serverSocket->errorString();
  53.  
  54. }
  55. else
  56. {
  57. delete serverSocket;
  58. }
  59. }
  60.  
  61. void PolaczenieSSL::gotowy()
  62. {
  63. qDebug()<<"gotowy";
  64. }
#ifndef POLACZENIESSL_H #define POLACZENIESSL_H #include <QTcpServer> #include <QTcpSocket> #include <QSslSocket> #include <QFile> #include <QSslKey> #include <QAbstractSocket> class PolaczenieSSL : public QTcpServer Q_OBJECT public: PolaczenieSSL(QWidget *parent = 0); ~PolaczenieSSL(); private: void incomingConnection(int port); private slots: void gotowy(); #endif // POLACZENIESSL_H //CPP #include "polaczeniessl.h" PolaczenieSSL::PolaczenieSSL(QWidget *parent) PolaczenieSSL::~PolaczenieSSL() void PolaczenieSSL::incomingConnection(int port) qDebug()<<"incomingConnection"; QSslSocket *serverSocket = new QSslSocket; serverSocket->setProtocol(QSsl::AnyProtocol); serverSocket->ignoreSslErrors(); QFile *file = new QFile("server.key"); QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server"); serverSocket->setPrivateKey(key); serverSocket->setLocalCertificate("server.csr"); serverSocket->addCaCertificates("/etc/ssl/certs"); if (serverSocket->setSocketDescriptor(port)) connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy())); serverSocket->startServerEncryption(); qDebug()<<serverSocket->errorString(); delete serverSocket; void PolaczenieSSL::gotowy() qDebug()<<"gotowy";
To copy to clipboard, switch view to plain text mode
On console, when client started connection:
Qt Code: Switch view
  1. incomingConnection
  2. "Unknown error"
incomingConnection 
"Unknown error"
To copy to clipboard, switch view to plain text mode
What is it wrong?
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
A minimal amount of code unrelated to your project that suffers from the same problem as your project. It is usually assembled by stripping down everything unrelated to the problem from your project and then eliminating pieces of code until the code starts working. Then you'll have your minimal example.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
You are using ignoreSslErrors() incorrectly, that's for sure but the real problem is elsewhere.
You are calling:
Qt Code: Switch view
  1. qDebug()<<serverSocket->errorString();
qDebug()<<serverSocket->errorString();
To copy to clipboard, switch view to plain text mode
And my question is, what would you expect to get as a result of this method for a connection without errors? I can tell you errorString() returns a textual description of QAbstractSocket::SocketError, so the real question is what value of QAbstractSocket::SocketError would you like to receive for a connection without errors?
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
Thanks for stating the problem, so far you just said you didn't undestand why you were getting the "unknown error" message.
First of all monitor state changes of sockets so that you know in what part of connection establishment your sockets currently are.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
  1. #include "polaczeniessl.h"
  2.  
  3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
  4. {
  5.  
  6. }
  7. PolaczenieSSL::~PolaczenieSSL()
  8. {
  9.  
  10. }
  11. void PolaczenieSSL::incomingConnection(int port)
  12. {
  13. qDebug()<<"incomingConnection";
  14. QSslSocket *serverSocket = new QSslSocket;
  15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
  16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
  17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
  18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
  19. serverSocket->setProtocol(QSsl::AnyProtocol);
  20. //serverSocket->ignoreSslErrors();
  21. QFile *file = new QFile("server.key");
  22. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
  23. serverSocket- >setPrivateKey(key);
  24. serverSocket->setLocalCertificate("server.csr");
  25. serverSocket->addCaCertificates("/etc/ssl/certs");
  26. if (serverSocket->setSocketDescriptor(port))
  27. {
  28. serverSocket->startServerEncryption();
  29. }
  30. else
  31. {
  32. delete serverSocket;
  33. }
  34. }
  35.  
  36. void PolaczenieSSL::gotowy()
  37. {
  38. qDebug()<<"gotowy";
  39. }
  40. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
  41. {
  42. qDebug()<<"Stan: "<<state;
  43. }
  44. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
  45. {
  46. qDebug()<<"Blad: "<<err;
  47. }
  48. void PolaczenieSSL::bledySSL(QList<QSslError> l)
  49. {
  50. for(int i=0;i<l.size();++i)
  51. qDebug()<<"BladSSL: "<<l.at(i);
  52. }
#include "polaczeniessl.h"
PolaczenieSSL::PolaczenieSSL(QWidget *parent)
PolaczenieSSL::~PolaczenieSSL()
void PolaczenieSSL::incomingConnection(int port)
    qDebug()<<"incomingConnection";
    QSslSocket *serverSocket = new QSslSocket;
    connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    serverSocket->setProtocol(QSsl::AnyProtocol);
    //serverSocket->ignoreSslErrors();
    QFile *file = new QFile("server.key");
    QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    serverSocket->setPrivateKey(key);
    serverSocket->setLocalCertificate("server.csr");
    serverSocket->addCaCertificates("/etc/ssl/certs");
    if (serverSocket->setSocketDescriptor(port))
        serverSocket->startServerEncryption();
        delete serverSocket;
void PolaczenieSSL::gotowy()
    qDebug()<<"gotowy";
void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    qDebug()<<"Stan: "<<state;
void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    qDebug()<<"Blad: "<<err;
void PolaczenieSSL::bledySSL(QList<QSslError> l)
    for(int i=0;i<l.size();++i)
    qDebug()<<"BladSSL: "<<l.at(i);
To copy to clipboard, switch view to plain text mode 
Qt Code: Switch view
  1. incomingConnection
  2. Stan: QAbstractSocket::ConnectedState
  3. Blad: QAbstractSocket::SocketError( 13 ) // The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)
  4. Stan: QAbstractSocket::UnconnectedState
incomingConnection 
Stan:  QAbstractSocket::ConnectedState 
Blad:  QAbstractSocket::SocketError( 13 ) // The SSL/TLS handshake failed, so the connection was closed (only used in QSslSocket)
Stan:  QAbstractSocket::UnconnectedState
To copy to clipboard, switch view to plain text mode 
I do not know why QList<QSslError> l is empty.
  1. connect(serverSocket, SIGNAL(sslErrors(QList<SslError>()), serverSocket, SLOT(ignoreSslErrors()));
connect(serverSocket, SIGNAL(sslErrors(QList<SslError>()), serverSocket, SLOT(ignoreSslErrors()));
To copy to clipboard, switch view to plain text mode 
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
  1. #include "polaczeniessl.h"
  2.  
  3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
  4. {
  5.  
  6. }
  7. PolaczenieSSL::~PolaczenieSSL()
  8. {
  9.  
  10. }
  11. void PolaczenieSSL::incomingConnection(int port)
  12. {
  13. qDebug()<<"incomingConnection";
  14. QSslSocket *serverSocket = new QSslSocket;
  15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
  16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
  17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
  18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
  19. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
  20. serverSocket->setProtocol(QSsl::AnyProtocol);
  21. //serverSocket->ignoreSslErrors();
  22. QFile *file = new QFile("server.key");
  23. QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
  24. serverSocket->setPrivateKey(key);
  25. serverSocket->setLocalCertificate("server.csr");
  26. serverSocket->addCaCertificates("/etc/ssl/certs");
  27. if (serverSocket->setSocketDescriptor(port))
  28. {
  29. serverSocket->startServerEncryption();
  30. }
  31. else
  32. {
  33. delete serverSocket;
  34. }
  35. }
  36.  
  37. void PolaczenieSSL::gotowy()
  38. {
  39. qDebug()<<"gotowy";
  40. }
  41. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
  42. {
  43. qDebug()<<"Stan: "<<state;
  44. }
  45. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
  46. {
  47. qDebug()<<"Blad: "<<err;
  48. }
  49. void PolaczenieSSL::bledySSL(QList<QSslError> l)
  50. {
  51. for(int i=0;i<l.size();++i)
  52. qDebug()<<"BladSSL: "<<l.at(i);
  53. }
#include "polaczeniessl.h"
PolaczenieSSL::PolaczenieSSL(QWidget *parent)
PolaczenieSSL::~PolaczenieSSL()
void PolaczenieSSL::incomingConnection(int port)
    qDebug()<<"incomingConnection";
    QSslSocket *serverSocket = new QSslSocket;
    connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
    serverSocket->setProtocol(QSsl::AnyProtocol);
    //serverSocket->ignoreSslErrors();
    QFile *file = new QFile("server.key");
    QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    serverSocket->setPrivateKey(key);
    serverSocket->setLocalCertificate("server.csr");
    serverSocket->addCaCertificates("/etc/ssl/certs");
    if (serverSocket->setSocketDescriptor(port))
        serverSocket->startServerEncryption();
        delete serverSocket;
void PolaczenieSSL::gotowy()
    qDebug()<<"gotowy";
void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    qDebug()<<"Stan: "<<state;
void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    qDebug()<<"Blad: "<<err;
void PolaczenieSSL::bledySSL(QList<QSslError> l)
    for(int i=0;i<l.size();++i)
    qDebug()<<"BladSSL: "<<l.at(i);
To copy to clipboard, switch view to plain text mode 
It is not working.
Your biological and technological distinctiveness will be added to our own. Resistance is futile.
Please ask Qt related questions on the forum and not using private messages or visitor messages.
  1. #include "polaczeniessl.h"
  2.  
  3. PolaczenieSSL::PolaczenieSSL(QWidget *parent)
  4. {
  5.  
  6. }
  7. PolaczenieSSL::~PolaczenieSSL()
  8. {
  9.  
  10. }
  11. void PolaczenieSSL::incomingConnection(int port)
  12. {
  13. qDebug()<<"incomingConnection";
  14. QSslSocket *serverSocket = new QSslSocket;
  15. connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
  16. connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
  17. connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
  18. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
  19. connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
  20. serverSocket->setProtocol(QSsl::AnyProtocol);
  21. /*
  22.   QFile *file = new QFile("server.key");
  23.   QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
  24.   serverSocket->setPrivateKey(key);
  25.   serverSocket->setLocalCertificate("server.csr");
  26.   serverSocket->addCaCertificates("/etc/ssl/certs");
  27.   */
  28. if (serverSocket->setSocketDescriptor(port))
  29. {
  30. serverSocket->startServerEncryption();
  31. }
  32. else
  33. {
  34. delete serverSocket;
  35. }
  36. }
  37.  
  38. void PolaczenieSSL::gotowy()
  39. {
  40. qDebug()<<"gotowy";
  41. }
  42. void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
  43. {
  44. qDebug()<<"Stan: "<<state;
  45. }
  46. void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
  47. {
  48. qDebug()<<"Blad: "<<err;
  49. }
  50. void PolaczenieSSL::bledySSL(QList<QSslError> l)
  51. {
  52. for(int i=0;i<l.size();++i)
  53. qDebug()<<"BladSSL: "<<l.at(i);
  54. }
#include "polaczeniessl.h"
PolaczenieSSL::PolaczenieSSL(QWidget *parent)
PolaczenieSSL::~PolaczenieSSL()
void PolaczenieSSL::incomingConnection(int port)
    qDebug()<<"incomingConnection";
    QSslSocket *serverSocket = new QSslSocket;
    connect(serverSocket, SIGNAL(encrypted()), this, SLOT(gotowy()));
    connect(serverSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),SLOT(stany(QAbstractSocket::SocketState)));
    connect(serverSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(bledy(QAbstractSocket::SocketError)));
    connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)),this,SLOT(bledySSL(QList<QSslError>)));
    connect(serverSocket,SIGNAL(sslErrors(QList<QSslError>)), serverSocket, SLOT(ignoreSslErrors()));
    serverSocket->setProtocol(QSsl::AnyProtocol);
    QFile *file = new QFile("server.key");
    QSslKey key(file, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, "server");
    serverSocket->setPrivateKey(key);
    serverSocket->setLocalCertificate("server.csr");
    serverSocket->addCaCertificates("/etc/ssl/certs");
    if (serverSocket->setSocketDescriptor(port))
        serverSocket->startServerEncryption();
        delete serverSocket;
void PolaczenieSSL::gotowy()
    qDebug()<<"gotowy";
void PolaczenieSSL::stany(QAbstractSocket::SocketState state)
    qDebug()<<"Stan: "<<state;
void PolaczenieSSL::bledy(QAbstractSocket::SocketError err)
    qDebug()<<"Blad: "<<err;
void PolaczenieSSL::bledySSL(QList<QSslError> l)
    for(int i=0;i<l.size();++i)
    qDebug()<<"BladSSL: "<<l.at(i);
To copy to clipboard, switch view to plain text mode 
It is not working.
Qt Code: Switch view
  1. incomingConnection
  2. Stan: QAbstractSocket::ConnectedState
  3. Blad: QAbstractSocket::SocketError( 13 )
  4. Stan: QAbstractSocket::UnconnectedState
incomingConnection 
Stan:  QAbstractSocket::ConnectedState 
Blad:  QAbstractSocket::SocketError( 13 ) 
Stan:  QAbstractSocket::UnconnectedState
To copy to clipboard, switch view to plain text mode 
  1. Stan: QAbstractSocket::HostLookupState
  2. Stan: QAbstractSocket::ConnectingState
  3. Stan: QAbstractSocket::ConnectedState
  4. Mode: 1
  5. Blad: QAbstractSocket::RemoteHostClosedError
  6. Stan: QAbstractSocket::ClosingState
  7. Stan: QAbstractSocket::UnconnectedState
Stan:  QAbstractSocket::HostLookupState 
Stan:  QAbstractSocket::ConnectingState 
Stan:  QAbstractSocket::ConnectedState 
Mode:  1 
Blad:  QAbstractSocket::RemoteHostClosedError 
Stan:  QAbstractSocket::ClosingState 
Stan:  QAbstractSocket::UnconnectedState
To copy to clipboard, switch view to plain text mode