PDA

View Full Version : Does Qt widgets work without it's main Event loop?



slscripters
9th June 2010, 07:15
Hi,

Does anybody have any idea if Qt widgets still work without enabling Qt's main Event loop? Like for example, I will have a custom main Event loop and Qt is only used for drawing only? And if possible, my main Event loop's events are passed to Qt widgets, like key press events.

Or does Qt only works as a stand-alone application, and it can't be used only for screen drawing purposes alone. :confused:

high_flyer
9th June 2010, 08:38
it depends what you mean with "work".

But, the question is, why do you want to use a custom event loop instead of adding your events the Qt event loop.
Its my guess, that if you review your needs and goals, a custom event loop will not be the correct way to go, but I can't say, since you didn't explain the reasoning behind your question.

slscripters
10th June 2010, 02:18
high_flyer,

Sorry for not being clear. Thanks for your initial answer. What I mean by "work" is that will the widgets still at least draw on the screen even if Qt's main event loop is disabled?

My reason for doing this is that I have this existing c++ program that can already act as an event loop. It receives system-wide and application-wide events and manages them. I would like to have a GUI for this c++ program and I chose Qt framework to build this. So I was planning to reuse this c++ program's event loop and just use Qt for drawing purposes only.

I've an experience in creating customized GUI frameworks and I'm not confident in doing the above method(disabling the event loop of Qt). Because in my experience, at least the drawing of the widgets are sometimes driven by timers.

If I'm not wrong, if I will not use Qt's main event loop, then its like reinventing it. Again my question is, will the widgets still work even if its main event loop is disabled? I've tried creating a simple hello world program and creating a simple QDialog with an endless loop that acts as the main loop of the main thread. Unfortunately, Qt requires a QApplication to be created and its "exec" function to be called. :confused:

high_flyer
10th June 2010, 08:35
Unfortunately, Qt requires a QApplication to be created and its "exec" function to be called
That is true, and AFAIK you can't avoid it if you are creating a Qt project.
The "correct" way to do what you want is to subclass QApplication and re-implement its event loop.
Not something I would recommend.

Does your application have a GUI, or is it a console application?
If its a console application you can use your console application in your Qt GUI as a QProcess, or might go for a server-client configuration, where the Qt app or .DLL/.so only do the GUI front end, as one idea.
If you are under Linux DBus might also be an idea.