[Qt-interest] Problem with FD_SET and select

Flavio Ceolin flavio.ceolin at gmail.com
Fri Sep 18 04:33:58 CEST 2009


Hi people,

I'm  trying to using serial port on an POSIX system (MACOSX) with qt.
I have a a thread that read data from serial. The code is this:

void ThreadCommRead::run()
{
	fd_set fds;
	int aux=0;
	FD_ZERO(&fds);
	FD_SET(m_handle,&fds);  	
	while(running){
		aux = select(m_handle+1,&fds,NULL,NULL,&timer);
		if(aux>0){
			m_mutex->lock();
			if((nbytes = read(m_handle,buffer,BUFFERSIZE))>0)
			emit dataRead(buffer,nbytes);
			m_mutex->unlock();
		}
	}
}

The problem is that the behavior of function FD_SET is wrong and aux  
never is different of zero.
I did a simple app for terminal and the same code using pthreads works  
fine.
I think that mainloop of qt application is disturbing.
Someone can help me?


Flavio Ceolin
skype: flavio.ceolin
msn: flavio.ceolin at hotmail.com
phone: +55 14 32276948
mobile:  +55 13 97044877
flavio.ceolin at gmail.com







More information about the Qt-interest-old mailing list