Results 1 to 4 of 4

Thread: Resize caught by select()

  1. #1
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Resize caught by select()

    For some reason if I start a select() statement while I'm resizing my QMainWindow, the select() returns instantly and my recvfrom command hangs.

    Is there anyway a resizeEvent would put info on a port somehow?

    I'm wondering if there is a way to check if the window is getting resized, but this seems like a kludge because I'm not sure what other events would do this as well.

    Here is my select function that calls itself every check_interval:

    Qt Code:
    1. void MyClient::checkForData() {
    2. logEvent( "About to check for data.", 2 );
    3. char rbuffer[1024];
    4. struct sockaddr_in from;
    5. size_t fromlen = sizeof( from );
    6.  
    7. // set up variables to make the select call
    8. struct timeval tv;
    9. tv.tv_sec = wait_time_seconds; // how long to wait
    10. tv.tv_usec = wait_time_microseconds;
    11. fd_set read_fds;
    12. FD_SET( sock, &read_fds );
    13. logEvent( "Checking for data.", 1 );
    14.  
    15. int num_responses = 0;
    16. if ( num_responses = select( sock+1, &read_fds, NULL, NULL, &tv ) > 0 ) {
    17. logEvent( QString( "Received data on %1 sockets." ).arg( num_responses ), 2 );
    18. recvfrom( sock, &rbuffer, sizeof( rbuffer ), 0, (struct sockaddr *) &from, &fromlen );
    19. QString the_response( rbuffer );
    20. logEvent( "The response: '" + the_response + "'", 4 );
    21. emit responseReady( the_response );
    22. } else {
    23. logEvent( "No response.", 4 );
    24. }
    25.  
    26. QTimer::singleShot( check_interval, this, SLOT( checkForData() ) );
    27. }
    To copy to clipboard, switch view to plain text mode 

    If I resize it when the code checks the socket with the select call I only see:

    About to check for data.
    Checking for data.
    Received data on 1 sockets.
    And then it freezes.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resize caught by select()

    i think the timer is giving you a infinite recursion, BTW why dont you use QTcpSocket?

  3. The following user says thank you to nish for this useful post:

    mhoover (17th July 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resize caught by select()

    Interesting. It would definitely be a bug in the timer because it works fine at 1 Hz as long as I don't resize the window.

    I'm not using QUdpSocket because I had this issue:

    http://www.qtcentre.org/forum/f-qt-p...ght=QUdpSocket

    Which is basically that I could read and write everything I wanted to using QUdpSocket except the case where I was getting a response from a Scheme server. (I could get scheme messages, but not if they were in response to something, and I got responses fine from a Qt based server).

  5. #4
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Resize caught by select()

    Ah ... It turns out Unix is often doing things with descriptors when you have GUI events and this can get picked up by a select() function even when the fd you pass to select() has not had any activity.

    My solution (workaround?) for now is to pass a MSG_DONTWAIT to the recvfrom function. This can return garbage, so you have to check the number of bytes.


    Qt Code:
    1. if ( recvfrom( sock, &rbuffer, sizeof( rbuffer ), MSG_DONTWAIT, (struct sockaddr *) &from, &fromlen ) > 0 ) {
    2. ...
    To copy to clipboard, switch view to plain text mode 

    Another thing would be to check if an EAGAIN error was returned, but I don't know how to do that.

    I'm surprised I couldn't call something to see if there's something waiting on the socket with out blocking/waiting. In Qt land there's something like that (readyForRead() or something), but I guess there's no equivalent for berkeley sockets.

Similar Threads

  1. Disable resize events
    By myrky in forum Qt Programming
    Replies: 7
    Last Post: 26th June 2009, 12:49
  2. Replies: 1
    Last Post: 10th August 2008, 18:55
  3. Replies: 2
    Last Post: 22nd January 2008, 16:10
  4. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.