Results 1 to 3 of 3

Thread: QSslSocket readyRead() signal problem

  1. #1
    Join Date
    Mar 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Question QSslSocket readyRead() signal problem

    Hi all,
    I'm writing a client application and ofc I need to read data from server.
    When I get signal readyRead() i just read data.
    The problem apears when serwer sends larger data.
    Larger means 128bytes + header (6bytes).
    In that case the signal "readyRead()" doesnt occure.
    Additionaly after sending another data after this larger data, still signal doesnt show, when at start everything works great.
    I also tryid with setting size of ReadBuffer manual but this doesnt help.
    Did someone have problem like that or know how to make it work with larger data?
    I tested it with 2 server: (1st in java, 2nd in qt), on both there is the same problem. So i think it must be client server.

  2. #2
    Join Date
    Dec 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QSslSocket readyRead() signal problem

    Hi Dear
    use this code:

    class APHTTP : public QHttp
    {
    Q_OBJECT

    rivate:
    QString mHost;
    QHttpRequestHeader mHeader;
    QSslSocket socket;

    public slots:
    void findPageGet();
    void socketReadyRead();
    void socketEncrypted();
    void sslErrors(QList<QSslError>);
    void socketStateChanged(QAbstractSocket::SocketState);
    }

    APHTTP::APHTTP()
    {
    mHost = "localhost";
    connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)) ,
    this, SLOT(socketStateChanged(QAbstractSocket::SocketSta te)));
    connect(&socket, SIGNAL(encrypted()),
    this, SLOT(socketEncrypted()));
    connect(&socket, SIGNAL(sslErrors(QList<QSslError>)),
    this, SLOT(sslErrors(QList<QSslError>)));
    connect(&socket, SIGNAL(readyRead()),
    this, SLOT(socketReadyRead()));

    socket.connectToHostEncrypted(mHost, 443, QIODevice::ReadWrite);
    socket.waitForConnected();
    socket.startClientEncryption();
    if (!socket.waitForEncrypted())
    {
    qDebug() << socket.errorString();
    return ;
    }
    this->setSocket(&socket);
    connect(this, SIGNAL(done(bool)), this, SLOT(findPageGet()));
    // you should set header!!!!!!!!!
    this->setHost(mHost, QHttp::ConnectionModeHttp);
    this->request(mHeader);
    }

    void APHTTP::findPageGet()
    {
    QByteArray bytData;
    QMutex mutex;
    QString body;

    bytData = this->readAll();
    body = QString::QString(bytData);
    this->deleteLater();
    }

    void APHTTP::socketReadyRead()
    {
    QString str;

    str = QString::fromUtf8(socket.readAll());
    }

    void APHTTP::sslErrors( QList<QSslError> error)
    {
    }

    void APHTTP::socketEncrypted()
    {
    }

    void APHTTP::socketStateChanged( QAbstractSocket::SocketState state )
    {
    }

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSslSocket readyRead() signal problem

    I would suggest to use QNetworkAccessManager instead of QHttp. The latter is deprecated and the former can handle SSL itself.

    Cheers,
    _

Similar Threads

  1. QUdpSocket readyRead() signal not triggered
    By deionut in forum Newbie
    Replies: 2
    Last Post: 26th October 2010, 18:19
  2. QNetworkReply & delayed readyRead(() signal
    By dmini in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 13:47
  3. Replies: 10
    Last Post: 9th July 2009, 12:05
  4. Replies: 1
    Last Post: 9th July 2009, 08:59
  5. readyRead signal too slow or what?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 6th July 2007, 19:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.