Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Windows message loop instead of QApplication::exec() / QApplication::processEvents()
Forum Updated to NodeBB v4.3 + New Features

Windows message loop instead of QApplication::exec() / QApplication::processEvents()

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    terenty
    wrote on 14 May 2013, 07:12 last edited by
    #1

    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!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      terenty
      wrote on 29 Jul 2013, 13:51 last edited by
      #2

      [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 :)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved