Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Know data sent with QSslSocket



  • Hello,

    I send data through QSslSocket with QTextStream,

    QTextStream t;	
    t.setDevice(_sslSocket);
    t.flush();
    

    It's Ok.
    But is there a signal to know bytes sent, for make a progress form ?
    encryptedBytesWritten(qint64 written) emit at the end of send.

    Thanks!


  • Moderators

    hi @cfdev QSslSocket is derived from QIODevice, so it should emit a void QIODevice::bytesWritten(qint64 bytes) signal that you can listen to.



  • @cfdev said in Know data sent with QSslSocket:

    encryptedBytesWritten(qint64 written) emit at the end of send.

    Is the encrypted data "big enough" to expect the signal to be emitted multiple times?

    What values do you receive for argument "written" when the signal is emitted? What's the size of your encrypted data?

    you may want to look at this answer regarding differences for encryptedBytesWritten() and bytesWritten() for both QTcpSocket and QSslSocket.



  • @J-Hilk encryptedBytesWritten() or bytesWritten() are emitted once, not in progress...
    Arf... After I used

    _sslSocket->waitForReadyRead( _timeout )
    

    maybe this block the signal emitted...



  • @Pablo-J.-Rogina
    | Is the encrypted data "big enough" to expect the signal to be emitted multiple times?
    %Yes, 9Mo

    | What values do you receive for argument "written" when the signal is emitted? What's the size of your encrypted data?
    Recieved once : 9108704 bytes, And apparently I receive this At the start of send, then nothing...

    encryptedBytesWritten() and bytesWritten() works similary for me juste the size change.



  • I found this on the doc https://doc.qt.io/qt-5/qiodevice.html#bytesWritten :

    bytesWritten() is not emitted recursively; if you reenter the event loop or call waitForBytesWritten() inside a slot connected to the bytesWritten() signal, the signal will not be reemitted (although waitForBytesWritten() may still return true).
    

    my process:

    QTextStream t;	
    t.setDevice(_sslSocket);
    t.flush();
    _sslSocket->waitForReadyRead( _timeout ) // Here I waiting the reply of server, but I don't any informations of my send...
    

    So, how do you control your send ?


  • Lifetime Qt Champion

    @cfdev

    If you are not in a thread, don't use the waitFor... functions. And never mix Signals&Slots with the waitFor... functions.

    In 99% of cases you are best with Signals&Slots alone.



  • @aha_1980 I'm in a other Thread to avoid block my main gui thread

    Instead of "waitFor" I try to use this:

    while( _sslSocket->bytesToWrite() ) {
    	qDebug() << "_sslSocket->bytesToWrite() : " << _sslSocket->bytesToWrite();
    	QThread::msleep(500);
    }
    

    I never out of this loop and the bytesToWrite never count down... why ?


  • Lifetime Qt Champion

    @cfdev If you are in another thread, you can use the waitFor... functions. But then you cannot use the signals. Please stick to one of them.



  • @aha_1980 Ok thanks for your reply
    But If I don't use waitfor function only signal, (because I already use for error ..etc very useful) ,
    How waiting for bytes writing and reading instead ? bytesToWrite() seem doens't work...


Log in to reply