Win32/COM and translations in Qt
-
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.
-
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.