如何在Qt中使用QSerialDevice?

发布于 2024-08-30 12:03:23 字数 1465 浏览 9 评论 0原文

我正在尝试使用 Qt 中的 QSerialDevice 来连接到我的串行端口。我之前也尝试过QextSerialPort(它适用于Windows Vista,但不幸的是不适用于Windows XP..),但我需要一个支持XP、Vista和Win7的API... 我构建了库并以这种方式配置它:

CONFIG      += dll
CONFIG      += debug

我确实使用了 SVN 的当前版本(0.2.0 - 2010-04-05)和 0.2.0 zip 包。
构建库后,我将其复制到我的 Qt Libdir (C:\Qt\2009.05\qt\lib) 和 C:\Windows\system32。现在我尝试链接项目文件中的 lib:

LIBS += -lqserialdevice

我导入所需的标头(abstractserial.h)并使用我自己的 AbstractSerial,如下所示:

// 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);

问题是,如果我运行我的应用程序,它会立即崩溃并退出代码 -1073741515 (应用程序无法正确初始化)。这与我在 Windows XP 下使用 QextSerialPort 时遇到的错误相同(它适用于 Windows Vista)。
如果我使用发布配置和我的程序构建 QSerialDevice 库,它会立即崩溃,但退出代码为 -1073741819

有人可以帮助我使用此程序或使用另一种解决方案来让串行端口与 Qt 一起使用(可能是另一个 API 或其他东西吗? ) 否则我必须使用 Windows API 函数,这意味着我的程序无法在 UNIX 系统上运行..
如果您有 WinXP SP3 下 QextSerialPort 问题的解决方案,也欢迎他们;)

最好的祝福,
托比亚斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-09-06 12:03:23

Tobias,

尝试从 SVN 使用:
svn 签出 svn://scm.fireforge.net/svnroot/qserialdevice

Tobias,

try use from SVN:
svn checkout svn://scm.fireforge.net/svnroot/qserialdevice

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文