Windows message loop instead of QApplication::exec() / QApplication::processEvents()
-
Hello everybody!
Do I miss any Qt functionality if I substitute QApplication::exec() with standard Windows message loop implementation? This should clarify what I mean:The ususal "Qt" way to run event processing:
@int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Window w;
w.show();
return a.exec();
}@"Windows" way to run event processing:
@#include <Windows.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Window w;
w.show();MSG msg;
while(GetMessage(&msg, 0, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}return msg.wParam;
}@The above demonstrates having external message loop with respect to QApplication instance, while QApplication instance itself doesn't even have its own event loop at all.
In other words, if I have main .exe program (knowing nothing about Qt) with message loop and a .dll with Qt GUI and QApplication instance inside, will it be ok to let the external message loop from main .exe to handle events for Qt GUI?
Thanks in advance! -
[quote author="terenty" date="1368515555"]
In other words, if I have main .exe program (knowing nothing about Qt) with message loop and a .dll with Qt GUI and QApplication instance inside, will it be ok to let the external message loop from main .exe to handle events for Qt GUI?
Thanks in advance![/quote]I'll just answer myself in case it's usefull for somebody:
We have a main .exe module written in C# under .NET that runs event loop processing, and we have a couple of .dlls written in Qt/C++ that have a GUI "inside" (and a QApplication instance that is shared). QApplication::exec() is never called but all the events are successfully dispatched by the main .exe (.NET) module's event loop and all the Qt functionallity is present( signals/slots, threads, etc.)EDIT 1:
That worked for Qt 4.8.2 but for Qt 5.1.0 things are a little bit different. Now you have to call QApplication::processEvents() once because it performs some initial initialization on its first call( installs WindowsHook on GetMessage or PeekMessage ). And after that whoever calls GetMessage in your application Qt events get processes and you are golden :)