Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, July 2007
QSocketNotifier


Message 1 in thread

Hi,

we want to be notified about serial port receive events on a windows
plattform ( Windows XP SP2, Visual Studio 2003, QT 4.3.0 ).
we need the file handle for other classes, so we get the file descriptor
by using _open_osfhandle.
all is done without any error, but QSocketNotifier doesn't emit SIGNAL
activated if any data arrives.

is it a programming error or a windows problem?

thanks
Marko



the code fragment:

    HANDLE m_fileHandle;
    DCB m_config;
    int m_fileDescriptor;
    QSocketNotifier *m_socketNotifier;

    //open device
    m_fileHandle = CreateFileA( "COM1", GENERIC_READ|GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING , NULL );

    //config device - get current settings
    m_config.DCBlength = sizeof( DCB );
    GetCommState( m_fileHandle, &m_config );
    //config device - edit settings
    m_config.fBinary = true;
    m_config.fAbortOnError = false;
    m_config.fNull = false;
    //config device - apply settings
    SetCommState( m_fileHandle, &m_config );

    //other initialisation for serial port ( baud rate a.s.o. )

    //get filedescriptor
    m_fileDescriptor = _open_osfhandle( reinterpret_cast<intptr_t>(
m_fileHandle ), _O_RDWR );
    //create socketNotifier
    m_socketNotifier = new QSocketNotifier( m_fileDescriptor,
QSocketNotifier::Read, this );
    //connect
    connect( m_socketNotifier, SIGNAL( activated( int ) ), this, SLOT(
canRead( int ) ) );


--
 [ signature omitted ] 

Message 2 in thread

On Wednesday 04 July 2007 15:35:46 Marko Doering wrote:
> Hi,
>
> we want to be notified about serial port receive events on a windows
> plattform ( Windows XP SP2, Visual Studio 2003, QT 4.3.0 ).
> we need the file handle for other classes, so we get the file descriptor
> by using _open_osfhandle.
> all is done without any error, but QSocketNotifier doesn't emit SIGNAL
> activated if any data arrives.
>
> is it a programming error or a windows problem?

QSocketNotifier is implemented using the WinSock API, and I'm guessing that's 
why you don't see any activity, since you are passing a handle that is not a 
WinSock socket descriptor.

-- 
 [ signature omitted ]