Qt 5.1: QWinMigrate does not process events correctly in Dll project



  • Good morning everyone,

    I'm using Qt since years now and it was always straight forward. I really love this library :)

    But currently I have a problem with a project being migrated to Qt5.1 from Qt4. One part of this project is a plugin for an existing MFC application. To be able to launch dialogues in within this plugin I had used the QWinMigrate library and it worked very well with Qt4.

    Now I have migrated to Qt5.1 and it seems QWinMigrate does not process queued events anymore. It is reproducible with the examples in QWinmigrate. I did the following:

    • Build the project in 'qt-solutions\qtwinmigrate\examples\mfc\step1'
    • Ammend example qtdll to create and show a dialog instead of the MessageBox and build it:

    @
    [...]

    QWinWidget * g_win;

    // Dialog with an OK and a Cancel Button. Class definition is skipped here.
    CDialog *g_dialog;

    BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /lpvReserved/ )
    {
    static bool ownApplication = FALSE;

    if ( dwReason == DLL_PROCESS_ATTACH )
    

    ownApplication = QMfcApp::pluginInstance( hInstance );
    if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
    {
    delete g_dialog;
    delete g_win;
    delete qApp;

    }
    
    return TRUE;
    

    }

    extern "C" __declspec(dllexport) bool showDialog( HWND parent )
    {
    g_win = new QWinWidget( parent );
    g_win->showCentered();

    g_dialog = new CDialog(win);
    g_dialog->show();
    

    }
    @

    If you run now the MFC executable build in step 1 and press on "about" it should load the library "qtdialog.dll" which itself open the child CDialog. But then, CDialog is completely unresponsive. You can click on the buttons, etc but nothing happens, not even close. Not any of the events are processed.

    Only if I move or resize the parent MFC window or something similar, events of the child are processed.

    I rechecked with Qt 4.8.4 and with this one everything is fine, but Qt 5.1 has this weird behavior.

    I looked into the code of class QMFCApp. Qt's event loop is triggered by installing a hook procedure monitoring WH_GETMESSAGE:
    @
    QT_WA({
    hhook = SetWindowsHookExW(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
    }, {
    hhook = SetWindowsHookExA(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
    });
    @

    which fires the following callback and triggers the event processing:

    @
    LRESULT CALLBACK QtFilterProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    if (qApp) {
    // don't process deferred-deletes while in a modal loop
    if (modalLoopCount)
    qApp->sendPostedEvents();
    else
    qApp->sendPostedEvents(0, -1);
    }

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

    }
    @

    So the events should be processed correctly (which actually works in Qt4). Could somebody confirm I did nothing wrong and is it worth to raise a bug?



  • Hi Roland W
    I am seeing the same behavior i.e messages from dll project are not processed, i.e I can see my dialogs but when buttons are clicked nothing happens.

    Did you manage to resolve this issue



  • Hi Elizabeta,

    see QTBUG-32962 for further details and a dirty workaround. When I have more time this week I maybe check again with 5.2 and prepare a proper fix.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.