Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Know data sent with QSslSocket

Know data sent with QSslSocket

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cfdevC Offline
    cfdevC Offline
    cfdev
    wrote on last edited by cfdev
    #1

    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!

    J.HilkJ Pablo J. RoginaP 2 Replies Last reply
    0
    • cfdevC cfdev

      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!

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • cfdevC cfdev

        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!

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @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.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        cfdevC 1 Reply Last reply
        2
        • cfdevC Offline
          cfdevC Offline
          cfdev
          wrote on last edited by cfdev
          #4

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

          _sslSocket->waitForReadyRead( _timeout )
          

          maybe this block the signal emitted...

          1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @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.

            cfdevC Offline
            cfdevC Offline
            cfdev
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • cfdevC Offline
              cfdevC Offline
              cfdev
              wrote on last edited by
              #6

              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 ?

              aha_1980A 1 Reply Last reply
              0
              • cfdevC cfdev

                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 ?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                Qt has to stay free or it will die.

                cfdevC 1 Reply Last reply
                5
                • aha_1980A aha_1980

                  @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.

                  cfdevC Offline
                  cfdevC Offline
                  cfdev
                  wrote on last edited by cfdev
                  #8

                  @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 ?

                  aha_1980A 1 Reply Last reply
                  0
                  • cfdevC cfdev

                    @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 ?

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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.

                    Qt has to stay free or it will die.

                    cfdevC 1 Reply Last reply
                    0
                    • aha_1980A aha_1980

                      @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.

                      cfdevC Offline
                      cfdevC Offline
                      cfdev
                      wrote on last edited by
                      #10

                      @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...

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved