Results 1 to 2 of 2

Thread: ambiguous documentation and behavior of QTcpSocket

  1. #1
    Join Date
    Jun 2010
    Location
    Germany, Munich
    Posts
    16
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Angry ambiguous documentation and behavior of QTcpSocket

    Hi There,
    I use currently Qt 4.5.2
    after a long exasperating time of coding I find some very oppositional statements in Qt Documentation.

    1.) Qt Assistant QTcpSocket / QAbstractSocket
    QTcpSocket hardy no sentence how to with threads
    2.) Qt Assistant Threaded Fortune Server Example

    Qt Code:
    1. void FortuneThread::run()
    2. {
    3. QTcpSocket tcpSocket;
    To copy to clipboard, switch view to plain text mode 
    What's worth noticing is that we are creating this object inside the thread, which automatically associates the socket to the thread's event loop. This ensures that Qt will not try to deliver events to our socket from the main thread while we are accessing it from FortuneThread::run().
    At this example it seems there ist no need to call "exec()" or, even not to use "exec()" ... will not deliver events to our socket for Main thread !

    3.) doc/threads.html and Qthread
    hreads to slots in this thread, using a mechanism called queued connections. It also makes it possible to use classes that require the event loop, such as QTimer and QTcpSocket, in the thread.
    If somebody reads and takes the Threaded Fortune Server Example he will struggle and fail very hard!

    On my specific problem I use
    Qt Code:
    1. MyThread::run()
    2. {
    3. while (running)
    4. {
    5. m_pFifio->getData( pBuffer, size );
    6. parseData( pData );
    7.  
    8. ... in some Object living in that thread I Call
    9. qint64 len = pTcpSocket->write ( data, length ) ;
    10.  
    11.  
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Where write() writes length bytes of data which never will appears on the other side of the socket ( some other (remote ) client programm ).
    One step better will be to append a waitForReadyRead() after write
    In deed QTcpSocket sends sends some data, but not complete tough write returns the correct amount of bytes.



    For me it dosn`t realy make sense that I have to bind QtcpSocket to event loop!
    It should go the normal (classic ) way to !

    Does sombody find a solution for this way
    regards

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

    Default Re: ambiguous documentation and behavior of QTcpSocket

    What exactly is ambiguous? If you are wondering why the threaded fortune server thread doesn't call exec() then I can tell you that is because it uses methods from the "waitFor" family that "emulate" the event loop for a particular socket. On the other hand if you created the socket in the main thread, called exec() on the application (from the main thread) and then called waitFor*() on the socket (or actually any other method) you would be creating a race condition between the two threads. The main thread would try to deliver events for the socket upon data arrival and at the same time you would be waiting for data to arrive in the other thread (in case of waitFor methods) and both these situations couldn't happen or you could be reading data from the socket's buffer at the same time the other thread was trying to write to this buffer taking the socket ot of sync. The documentation is clear about this provided you know what reentrancy is. If you don't then... well... you can only blame yourself, the docs can't explain it in docs for every of the over seven hundred classes in Qt.
    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.


Similar Threads

  1. ambiguous connect()
    By Cruz in forum Qt Programming
    Replies: 2
    Last Post: 27th August 2009, 12:35
  2. Adding Qt's documentation to Xcode documentation browser
    By fabietto in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2007, 16:38
  3. Strange QTcpSocket behavior (debugged with Ethereal)
    By mdecandia in forum Qt Programming
    Replies: 23
    Last Post: 28th May 2007, 21:44
  4. `QObject' is an ambiguous base of `ClientThread'
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2006, 14:17
  5. ambiguous call to overloaded function
    By :db:sStrong in forum Qt Programming
    Replies: 18
    Last Post: 10th February 2006, 10:36

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.