How to use QSerialDevice in Qt?

Posted by Tobias on Stack Overflow See other posts from Stack Overflow or by Tobias
Published on 2010-04-23T12:02:13Z Indexed on 2010/04/24 11:23 UTC
Read the original article Hit count: 1991

Hello,

I am trying to use QSerialDevice in Qt to get a connection to my serial port. I also tried QextSerialPort before (which works on Windows Vista but unfortunately not on Windows XP ..) but I need an API which supports XP, Vista and Win7... I build the library and configured it this way:

CONFIG      += dll
CONFIG      += debug

I did use the current version from SVN (0.2.0 - 2010-04-05) and the 0.2.0 zip package.
After building the library I did copy it to my Qt Libdir (C:\Qt\2009.05\qt\lib) and also to C:\Windows\system32. Now I try to link against the lib in my project file:

LIBS += -lqserialdevice

I import the needed header (abstractserial.h) and use my own AbstractSerial like this:

// Initialize
this->serialPort->setDeviceName("COM1");
if (!this->serialPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
  qWarning() << "Error" << this->serialPort->errorString();

// Configure SerialPort
this->serialPort->setBaudRate(AbstractSerial::BaudRate4800);
this->serialPort->setDataBits(AbstractSerial::DataBits8);
this->serialPort->setFlowControl(AbstractSerial::FlowControlOff);
this->serialPort->setParity(AbstractSerial::ParityNone);
this->serialPort->setStopBits(AbstractSerial::StopBits1);

The problem is, that if I run my application, it crashes immediately with exit code -1073741515 (application failed to initialize properly). This is the same error I got using QextSerialPort under Windows XP (it worked with Windows Vista).
If I build the QSerialDevice lib with release config and also my program, it crashes immediately but with exit code -1073741819

Can someone help me with this program or with another solution of getting a serial port to work with Qt (maybe another API or something?) Otherwise I have to use Windows API functions which would mean that my program won't work with UNIX systems..
If you have a solution for the problem with QextSerialPort under WinXP SP3, they are also welcome ;)

Best Regards,
Tobias

© Stack Overflow or respective owner

Related posts about qt

Related posts about c++