On 10/22/2012 03:16 AM, d3fault wrote:
A question to all: I have a GUI application. I need to do some task (for example, periodically reading/writing from a serial port) in the background that has nothing to do with GUI. i.e. the background task does not touch GUI or need to emit signals or have slots. It just needs to be there, reading & writing to shared memory (protected by Mutex). Now, the way I've been doing this is by creating a new class from QThread and overriding run() to implement my thread function. The function is often a loop that runs till a public volatile bool variable is set, indicating time to quit. For doing periodic stuff, it sleeps for few milliseconds (by using nanosleep()). When the program is terminated, in main windows' close event, or some other suitable place, I set the thread loop control variable and wait for the thread to terminate (QThread::wait()). Is there any other recommended or better way to do it? Note that I don't need to do any Qt stuff (update GUI, signals & slots etc.) in my 'worker' thread. regards, Syam |
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest