Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Win32/COM and translations in Qt
Forum Updated to NodeBB v4.3 + New Features

Win32/COM and translations in Qt

Scheduled Pinned Locked Moved Brainstorm
2 Posts 1 Posters 2.0k 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.
  • F Offline
    F Offline
    fralik
    wrote on last edited by
    #1

    Hi!

    I am currently using some code that is able to load DLL through COM, so it is pure Win32. However, I started to write my plugin in Qt for several reasons. Unfortunately, I can not just write everything in Qt, so COM-related code must be there.

    So far I am creating my QApplication with this code:
    @
    QApplication* app = NULL;
    HHOOK hhook;

    LRESULT CALLBACK QtFilterProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    if (qApp)
    {
    qApp->sendPostedEvents(0, -1);
    }

    return CallNextHookEx(hhook, nCode, wParam, lParam);
    

    }

    BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
    LPVOID lpReserved)
    {
    int argc = 0;
    char** argv = 0;
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:

        app = new QWinApplication(argc, argv);
        QT_WA(
        {
            hhook = SetWindowsHookExW(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
        },
        {
            hhook = SetWindowsHookExA(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
        });
        break;
    case DLL_THREAD_ATTACH:
        break;
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        UnhookWindowsHookEx(hhook);
        if (app)
        {
            app->quit();
            delete app;
        }
        break;
    }
    return TRUE;
    

    }
    @

    Then I am creating Widgets, installing translation just like in any other Qt application. Everything except translations works fine. I am sure that translation files are loaded successfully. If I build standalone .exe file instead of .dll, then GUI is translated. I tried to invoke retranslateUi function manually, but this also had no effect.

    The questions are:

    Does anyone have a clue why translation could fail even if .qm files are loaded and installed correctly?

    What possible events/messages do I miss to forward to my UI?

    Thanks.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fralik
      wrote on last edited by
      #2

      I figured out the problem. I was creating the QTranslator on stack in DllMain. Instead of this I should either create it on heap or make it static.

      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