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. Meaning of waitForReadyRead(-1)
QtWS25 Last Chance

Meaning of waitForReadyRead(-1)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 9.4k Views
  • 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.
  • G Offline
    G Offline
    Giomaca
    wrote on last edited by
    #1

    Hello everybody,
    I'm a newby in QT and I don't have much OPP experience.
    I'm developing a multithreading server application using QTcpServer Class based on the example "Threaded Fortune Server Application".

    As in the example in the run function of the thread I create a QTcpSocket object, initialize the socket and then use the function waitForReadyRead in order to wainting data to be read.
    In the follow you can see I'm using the waitForReadyRead function in run function

    @
    void CThread::run()
    {
    QTcpSocket tcpSocket;

    if (!tcpSocket->setSocketDescriptor(socketDescriptor))   //Socket Initialization:
    {                                                        //If error
        emit error(tcpSocket->error());                      //emit error
        return;                                              //and go out
    }
    
    while (!close)
    {
         if (tcpSocket->waitForReadyRead(-1))    //Waiting data to be read
         {
               DataServer = tcpSocket->readAll();        //Read all data
            
                 //... Data decoding ...
                 //...and answering...
         }
    }
    

    }
    @

    I used the waitForReadyRead() funcition specifying in the argument -1 because I'd like to stop the thread waiting new data.

    When I tried my application I found out that the thread didn't stop in waitForReadyRead() waiting for new data, but It worked like a time-out occours. So that, an infinte loop in while (!close) { ... } goes on.

    I'd like to know if I understood the meaning of waitForReadyRead or I missed something.

    Can someone help me?

    Thanks in advance.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      welcome to the forum

      waitForReadyRead will exit, when information is ready to read. So, if you are receiving a larger chunk of information it might exit several times.

      Also the description for this reimplementation does not refer to -1 "see here":http://doc.qt.nokia.com/4.7/qabstractsocket.html#waitForReadyRead
      it is only mentioned in "QIODevice":http://doc.qt.nokia.com/4.7/qiodevice.html#waitForReadyRead

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        The big question is: why do you do this? Why make your socket handling first asynchronic by putting it in a thread, and then use synchronic programming again within the thread? Why not use the asynchronic programming methods directly and get rid of both the thread and the waitFor* methods?

        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