Domanda

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.

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top