Results 1 to 4 of 4

Thread: saving data to server through QTcpSocket

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default saving data to server through QTcpSocket

    Qt Code:
    1. void myClient::readyRead()
    2. {
    3. //qDebug() << socket->readAll();
    4. QString fPath("location");
    5.  
    6. QByteArray block=socket->readAll();
    7. QString fName= QString(block);
    8. QFile sentFile(fPath +QDir::separator() + fName);
    9.  
    10. if(!sentFile.exists())
    11. {
    12. sentFile.open(QFile::WriteOnly);//check if size equal to size or overwrite
    13. while(socket->waitForReadyRead())
    14. {
    15. QByteArray block= socket->readAll();
    16. qDebug()<< "read: " << block.size();
    17. sentFile.write(block);
    18. block.clear();
    19. }
    20. socket->close();
    21. sentFile.close();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    i guess the while loop is blocking my GUI
    how can l make this code non-Blocking
    Thanks and best regards.
    Last edited by wysota; 6th January 2013 at 10:36. Reason: missing [code] tags

Similar Threads

  1. QTcpSocket/QTcpServer on a heavy load server
    By Eumcoz in forum Qt Programming
    Replies: 10
    Last Post: 7th August 2012, 19:36
  2. QTcpSocket get disconnected when server is sending huge data
    By KernelCoder in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2011, 08:45
  3. Replies: 0
    Last Post: 5th February 2011, 08:31
  4. Replies: 8
    Last Post: 18th December 2010, 15:07
  5. My server (using QTcpServer and QTcpSocket) crashes
    By supergillis in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2010, 15:32

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.