Qt 每 500ms 中断一次
我对 Qt 还很陌生。这是我正在编写的第二个“真正的”程序。我尝试使用 Qt 创建一个前端类,它是与串行端口通信的 .net 类的包装器。
基本上,用户选择他想要通过串行端口发送的全部内容,然后单击“开始”按钮。然后,程序进入一个长达四个小时的长循环,通过串行端口发送用户选择的命令。
我想知道我该如何进行以下操作: 1. 创建一个退出循环的按钮。 2. 每 500ms 调用一个函数(当程序处于循环中时)。
我研究过 QThreads,但我真的不知道如何使用它们。 QThreads 是正确的选择吗?我追求最简单的方法,因为我还不太精通 Qt。此外,我应该补充一点,我正在使用 Visual Studio 2010 的 Qt 插件。
感谢您的宝贵时间。
I'm fairly new to Qt. This is my second 'real' program that I'm writing. I've attempted to use Qt to create a frontend a class which is a wrapper around a .net class that talks to the serial port.
Basically, the user picks a whole stuff that he wants to send down the serial port, then clicks the 'start' qpushbutton. The program then goes into a long loop for four hours sending the commands chosen by the user down the serial port.
I would like to know how I can go about the following:
1. Create a button that exits the loop.
2. Call a function every 500ms (while the program is in the loop).
I have looked into QThreads, though I don't really know how to use them. Are QThreads the way to go? I am after the easiest way, as I am not yet that proficient with Qt. Furthermore, I should add that I'm using the Qt addon for Visual Studio 2010.
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,线程是可行的方法,除非您可以重写函数以更快返回,并在主循环中定期调用它。
如果您选择线程,请注意文档中与事件循环相关的部分,这也是您所需要的,因为它在幕后驱动信号槽关系。
顺便说一下,看看 QextSerialPort
Yes, the threads are the way to go, unless you can rewrite your function to return sooner, and call it periodically in the main loop.
If you go for threads, pay attention to event-loop-related part of the doc, it's what you'll also need, since it drives the signal-slot relations behind the scenes.
By the way, have a look at QextSerialPort