mhoover
17th July 2009, 01:37
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:
void MyClient::checkForData() {
logEvent( "About to check for data.", 2 );
char rbuffer[1024];
struct sockaddr_in from;
size_t fromlen = sizeof( from );
// set up variables to make the select call
struct timeval tv;
tv.tv_sec = wait_time_seconds; // how long to wait
tv.tv_usec = wait_time_microseconds;
fd_set read_fds;
FD_SET( sock, &read_fds );
logEvent( "Checking for data.", 1 );
int num_responses = 0;
if ( num_responses = select( sock+1, &read_fds, NULL, NULL, &tv ) > 0 ) {
logEvent( QString( "Received data on %1 sockets." ).arg( num_responses ), 2 );
recvfrom( sock, &rbuffer, sizeof( rbuffer ), 0, (struct sockaddr *) &from, &fromlen );
QString the_response( rbuffer );
logEvent( "The response: '" + the_response + "'", 4 );
emit responseReady( the_response );
} else {
logEvent( "No response.", 4 );
}
QTimer::singleShot( check_interval, this, SLOT( checkForData() ) );
}
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.
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:
void MyClient::checkForData() {
logEvent( "About to check for data.", 2 );
char rbuffer[1024];
struct sockaddr_in from;
size_t fromlen = sizeof( from );
// set up variables to make the select call
struct timeval tv;
tv.tv_sec = wait_time_seconds; // how long to wait
tv.tv_usec = wait_time_microseconds;
fd_set read_fds;
FD_SET( sock, &read_fds );
logEvent( "Checking for data.", 1 );
int num_responses = 0;
if ( num_responses = select( sock+1, &read_fds, NULL, NULL, &tv ) > 0 ) {
logEvent( QString( "Received data on %1 sockets." ).arg( num_responses ), 2 );
recvfrom( sock, &rbuffer, sizeof( rbuffer ), 0, (struct sockaddr *) &from, &fromlen );
QString the_response( rbuffer );
logEvent( "The response: '" + the_response + "'", 4 );
emit responseReady( the_response );
} else {
logEvent( "No response.", 4 );
}
QTimer::singleShot( check_interval, this, SLOT( checkForData() ) );
}
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.