Results 1 to 3 of 3

Thread: modeless dialog in qt dll loaded in existing non qt app

  1. #1
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default modeless dialog in qt dll loaded in existing non qt app

    Hello

    I am using
    - Qt 4.5 opensource
    - Qt/Mfc migration Framework. (open source edition)

    I want to make qt gui dll that will be loaded in non qt existing application for which I don't have source code.

    the code for the dll :

    Qt Code:
    1. #include <qmfcapp.h>
    2. #include <qwinwidget.h>
    3.  
    4. #include <QtGui/QMessageBox>
    5. BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID )
    6. {
    7. static bool ownApplication = FALSE;
    8. if ( dwReason == DLL_PROCESS_ATTACH )
    9. ownApplication = QMfcApp::pluginInstance( hInstance );
    10. if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
    11. delete qApp;
    12. return TRUE;
    13. }
    14.  
    15. void showqt(HWND parent)
    16. {
    17. QWinWidget* win=new QWinWidget( parent );
    18. win->showCentered();
    19. Ui::GoToCellDialog ui;
    20. QDialog *dialog = new QDialog(win);
    21. ui.setupUi(dialog);
    22. dialog->show();
    23. return ;
    24. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that the dialog is not shown at all, or sometimes it
    is shown and very quickly disappears . Note that when I am trying to use modal dialog (dialog->exec()) the dialog is shown .
    Maybe that is cause modal dialog has its own message loop,
    but i was expecting this will work cause I am merging the application loop with the qt loop with QMfcApp:: pluginInstance.

    Form the documentation :
    "The QMfcApp class also provides a static API pluginInstance() that drives the Qt event loop when loaded into an MFC or Win32 application. This is useful for developing Qt based DLLs or plugins, or if the MFC application's event handling can not be modified."

    Thanks
    Last edited by wysota; 28th July 2009 at 10:22. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: modeless dialog in qt dll loaded in existing non qt app

    You are creating your objects on stack and they go out of scope when you leave the function and are destroyed. Create the ui object on heap instead or make a proper QDialog subclass with embedded ui object and instantiate the dialog on heap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: modeless dialog in qt dll loaded in existing non qt app

    Thank you. It works

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 17
    Last Post: 2nd June 2009, 10:18
  3. Problem with Qt 4.5.1 and Windows 7 RC (Build 7100)
    By Paladin12 in forum Installation and Deployment
    Replies: 0
    Last Post: 13th May 2009, 09:58
  4. mysql 5 connection
    By GuL in forum Newbie
    Replies: 37
    Last Post: 18th August 2008, 15:11
  5. exception at 0x65100c40 (QtGuid4.dll)
    By sabeesh in forum Qt Programming
    Replies: 11
    Last Post: 21st December 2007, 17:10

Bookmarks

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.