[Development] What do you know about Qt::Device/IoHandle?

Alex Henrie alexhenrie24 at gmail.com
Tue Mar 12 02:07:53 CET 2013

Hi all,

I have been trying to get a patch accepted to QSerialPort:

Basically, my problem is that I want to use QSerialPort, but I need to
run the serial port in non-exclusive mode. My patch adds a handle()
function to get the serial port's file descriptor, much like
QFileDevice::handle(), QAbstractSocket::socketDescriptor(),
QWidget::winId(), and QProcess::pid(). Once I have the file
descriptor, disabling exclusive mode is a one-line call to ioctl.

There are essentially two ways to implement QSerialPort::handle():

1. Put #ifdef around the function prototype so that handle() returns
an int on Unix and a HANDLE (a.k.a. void*) on Windows. In the
documentation, do not specify handle()'s return type.

2. Define a new type analogous to WId and Q_PID for serial port
handles. Use #ifdef to make this type equivalent to int on Unix and
HANDLE or void* on Windows. Make handle() return this type.

QSerialPort's primary maintainer, Laszlo Papp, is in favor of option
#2, but says that it has to wait until a typedef Qt::Device/IoHandle
is added to QtCore. He says that this Qt::Device/IoHandle is going to
be for serial ports, parallel ports, bluetooth, and USB.

It seems to me that Qt::Device/IoHandle could only work as long as Qt
is not ported to any operating system that uses different data types
for serial port, parallel port, bluetooth, and USB handles. However,
Laszlo says that at least one QtCore developer supports this approach

The patch was submitted 3 weeks ago and the problem still exists, so
I'm bringing the question here. What do you know about
Qt::Device/IoHandle, and how would you implement



More information about the Development mailing list