Results 1 to 9 of 9

Thread: QTcpSocket and QProgressBar/QProgressDialog

  1. #1

    Default QTcpSocket and QProgressBar/QProgressDialog

    Hello, could you please clarify. I have QTcpServer class who's send the data, and QTcpSocket class who's received this data.

    I have a slot slotReadyRead() for ReadReady() signal like this:
    Qt Code:
    1. void MyClient::slotReadyRead()
    2. {
    3. QDataStream in(m_pTcpSocket);
    4. in.setVersion(QDataStream::Qt_4_8);
    5. for (;;) {
    6. if (!m_nNextBlockSize) {
    7. if (m_pTcpSocket->bytesAvailable() < (int)sizeof(quint64)) {
    8. break;
    9. }
    10. in >> m_nNextBlockSize;
    11. }
    12.  
    13. if (m_pTcpSocket->bytesAvailable() < m_nNextBlockSize) {
    14. break;
    15. }
    16. in >> bList; //QList
    17. m_nNextBlockSize = 0;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    and I wondering how I can get the values of received date for update some progress indicator?
    And second question, how it possible to increase the speed of transmitting data via QTcpSocket?

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by nikkadim View Post
    and I wondering how I can get the values of received date for update some progress indicator?
    You need to know how much data you expect to receive in total. Then when reading the data, calculate how much you already received and set those values on a progress bar.

    And second question, how it possible to increase the speed of transmitting data via QTcpSocket?
    Use something smarter than QDataStream. This is a really lame approach in terms of efficiency.
    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.


  3. #3

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by wysota View Post
    You need to know how much data you expect to receive in total. Then when reading the data, calculate how much you already received and set those values on a progress bar.


    Use something smarter than QDataStream. This is a really lame approach in terms of efficiency.
    Yes, theoretically I understand how I need to calculate, but my question was how!? May be some signals?
    I'm afraid I have to use QDataStream because I need to transfer complicated data structure (QList) via socket, and for this small app no reason to make my own functions.
    I think the speed issue did not correlate with QDataStream, my be with some settings, memory pre-allocation but not with QDataStream itself.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by nikkadim View Post
    Yes, theoretically I understand how I need to calculate, but my question was how!? May be some signals?
    It depends how you do the reading. The most basic aparatus you have is bytesAvailable().

    I'm afraid I have to use QDataStream because I need to transfer complicated data structure (QList) via socket, and for this small app no reason to make my own functions.
    You don't need QDataStream for that.

    I think the speed issue did not correlate with QDataStream, my be with some settings, memory pre-allocation but not with QDataStream itself.
    Data transfer time over network is directly proportional to the amount of data being transfered. The less data to transfer, the less time it takes.
    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.


  5. #5

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by wysota View Post
    It depends how you do the reading. The most basic aparatus you have is bytesAvailable().


    You don't need QDataStream for that.
    Do you have link to some code example for this?
    PS: Now I have receiving speed about 20 Mbit/s, at 1Gbit/s NIC. Test was performed on one machine.
    Last edited by nikkadim; 18th September 2012 at 16:19.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by nikkadim View Post
    Do you have link to some code example for this?
    No, I don't have link to any example code If you want an efficient protocol, it has to depend on what you are currently doing.

    The most trivial (but probably not a very clever) approach would be to simply memcpy() your structure to the socket and then do the same on the other end.

    PS: Now I have receiving speed about 20 Mbit/s, at 1Gbit/s NIC. Test was performed on one machine.
    I don't see how that's relevant to anything. Especially if you are sending to localhost which doesn't even use your network interface card.

    Either you have efficiency or ease of use. Choose which is more important for you.
    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.


  7. #7

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Looks like you recommend me don't use QT at all

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    No, I recommend you to use tools and mechanisms proper to the problem you are facing. I understand you took the code from some Qt example (e.g. fortune cookie) but this is very generic (and badly written) code that is not suited for problems more complex than reading a couple of bytes from the socket. If you know what structure of data you expect, then you really don't need to send the size of that structure to the socket and you don't need to go through generic serialization code that sometimes bloats the data sent unnecessarily (and obscures access to the data from non-Qt applications).
    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.


  9. #9
    Join Date
    Jun 2010
    Location
    Pretoria, South Africa
    Posts
    22
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket and QProgressBar/QProgressDialog

    Quote Originally Posted by nikkadim View Post
    I wondering how I can get the values of received date for update some progress indicator?
    You've got everything you need for this. You can create a signal like one from QFtp:

    Qt Code:
    1. void dataTransferProgress(qint64 done, qint64 total);
    To copy to clipboard, switch view to plain text mode 

    and then just emit the data you have: bytesAvailable() tells you how much data you have in the internal buffer; m_nNextBlockSize contains the data size you're expecting.

Similar Threads

  1. QTreeWidget and QProgressDialog?
    By progman in forum Newbie
    Replies: 6
    Last Post: 18th March 2010, 18:05
  2. How to execute a QProgressDialog once
    By franco.amato in forum Newbie
    Replies: 4
    Last Post: 16th March 2010, 16:36
  3. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 18:24
  4. QProgressDialog
    By samirg in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2007, 16:37
  5. qprogressDialog
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 14:16

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.