PDA

View Full Version : QTimer and QThread in Qtopia 4.2.0



mellibra
25th October 2007, 06:16
The case is I've got two event loops in application, one is Qtopia's GUI's event loop, the other is glib's event loop for network.

In Qtopia 2.2.0, I cannot use QThread because of our development environment configuration. So I use QTimer. When it's timeout,
g_main_context_iteration(g_main_context_default(), FALSE); will be called.

Now in Qtopia 4.4.0, when I port this code, compile, and run, It says QTimer should be used in thread started with QThread. Does that mean I must start a timer in an event loop? If I use one thread for GUI event loop, the other for listening network events to give user prompts, will this work?

wysota
25th October 2007, 07:32
Hmm.... Why do you need a separate event loop for networking? Qt4 uses glib event loop itself (if you compile it that way), so you are using a single loop even now. I just don't see the point of separate event loops... Could you explain?

mellibra
25th October 2007, 09:17
The library this application used is based on glib. It need an event loop to keep monitoring network and callback application. In Qtopia, QtopiaApplication::exec() maybe GUI event loop. I'm not sure this could also monitor network.

wysota
25th October 2007, 09:26
Qt/Qtopia contains networking classes. I'm sure you can use them instead of the glib dependency. But regardless of that if you use a glib-enabled Qt, the Qt event loop should work within the glib event loop without any special tricks to activate the loop. Just call QApplication::exec() and the loops should cooperate. At least that's how I understand it. There is even an article about it somewhere on Trolltech Labs or Qt Quarterly - you can try to dig it out...