Results 1 to 2 of 2

Thread: Events not processed using QMfcApp::pluginInstance

  1. #1
    Join Date
    Aug 2009
    Qt products

    Default Events not processed using QMfcApp::pluginInstance

    Hello, I'm trying to interface with a win32 app with a dll written using qt. All I'm trying to do for now is making a modeless QDialog display. I'm following the examples here:

    Here is the code for my DLL entry:
    Qt Code:
    1. BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved)
    2. {
    3. static bool ownApplication = FALSE;
    5. if ( fdwReason == DLL_PROCESS_ATTACH )
    6. {
    7. ownApplication = QMfcApp::pluginInstance( hInstance );
    9. char buffer[512];
    10. sprintf( buffer, "Creating MFC App - %d\n", ownApplication );
    11. OutputDebugStringA( buffer );
    12. }
    13. if ( fdwReason == DLL_PROCESS_DETACH && ownApplication )
    14. {
    15. OutputDebugString( TEXT("Deleting MFC App\n") );
    16. ownApplication = FALSE;
    17. delete qApp;
    18. }
    20. return (TRUE);
    21. }
    To copy to clipboard, switch view to plain text mode 

    To test that events are surely not being processed, I devised a test using this QDialog I wrote:
    Qt Code:
    1. class TestDialog : public QDialog
    2. {
    3. public:
    4. TestDialog( QWidget* pParent ) : QDialog( pParent, Qt::WindowStaysOnTopHint )
    5. {
    6. OutputDebugString( TEXT("Creating Test Dialog\n") );
    8. setWindowTitle( "This is a test" );
    9. resize( 800, 600 );
    10. setAttribute( Qt::WA_DeleteOnClose );
    11. setModal( false );
    12. show();
    13. close();
    14. }
    16. ~TestDialog()
    17. {
    18. // If Events are being processed, this should be outputted
    19. OutputDebugString( TEXT("Shutting Down Test Dialog\n") );
    20. }
    21. };
    To copy to clipboard, switch view to plain text mode 

    It is very simple, since I am setting the WA_DeleteOnClose flag, it should delete the dialog in the next event update after it has been closed. If events are being updated, the debugger should output that it is shutting down the Test Dialog. Here is the code I used to test it:

    Qt Code:
    1. QWinWidget* pWinWidget = new QWinWidget( hParentWnd );
    2. pWinWidget->center();
    4. // As a test to see if events work, see if this deletes itself (it doesn't)
    5. TestDialog* pTestDialog = new TestDialog( pWinWidget );
    7. // if this is uncommented, it gets deleted fine (events are processed)
    8. //qApp->exec();
    To copy to clipboard, switch view to plain text mode 

    The following code should work if events are being processed, however the destructor of TestDialog never gets called. When I call qApp->exec() manually though, the destructor does get called and the QDialog events all work perfectly. Being that this is a DLL into a win32 application, you can imagine how qApp->exec() takes over the message handling so this is not a good solution (for example, keyboard no longer works on the original win32 application). According to the docs, QMfcApp:: pluginInstance should be able to integrate into the message loop properly. Am I doing something wrong here?

  2. #2
    Join Date
    Aug 2009
    Qt products

    Default Re: Events not processed using QMfcApp::pluginInstance

    If anyone is interested it looks like I had a QApplication instantiated but not used, this was causing conflicts with the QApp in QMfcApp. As soon as I removed that unused QApplication everything managed all the events correctly.

Similar Threads

  1. Qt...Using Events
    By Peppy in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2009, 10:41
  2. Events
    By T0bi4s in forum Newbie
    Replies: 16
    Last Post: 25th November 2009, 23:09
  3. Events
    By SV in forum Qt Programming
    Replies: 0
    Last Post: 21st May 2008, 09:48
  4. QT Events
    By Sreeja in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2006, 09:25
  5. Events - how to
    By eleanor in forum Newbie
    Replies: 2
    Last Post: 13th November 2006, 08:23


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.