Results 1 to 3 of 3

Thread: Using Qt 5, how do I create a user interface (modeless dialog box) in a Qt DLL?

  1. #1
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Using Qt 5, how do I create a user interface (modeless dialog box) in a Qt DLL?

    I understand that the QtGUI has changed significantly from Qt4 to Qt5.
    • I want to create a DLL that has a user interface (GUI).
    • This DLL must work with third party applications that have their own user interface.
    • The third party applications can be written in Qt, .NET, MFC, and other programming languages other than C/C++.
    • I created a DLL that displays a modeless dialog box in Qt 4.8.4 and works as designed.
    • When I upgraded the DLL for Qt 5.1.1:
      • The widgets (combo-box, push button, check box) on the dialog box no longer respond to mouse clicks.
      • The frame is active and the dialog box can be moved around.
      • The window repaints when obscured/exposed by another window.
    • The model I am using was provided by the twain consortium and is similar to other sample code I located on this and other forums.


    For example, the main entry function in the DLL launches a thread for the QApplication:
    Qt Code:
    1. // Coerce the QCoreApplication instance if it exists to a QApplication.
    2. QApplication * pApp = qApp;
    3. if (pApp)
    4. {
    5. // Test for consistency between the application QT version and
    6. // the one for the DS.
    7. int nV1App = 0;
    8. int nV2App = 0;
    9. int nV3App = 0;
    10. SSCANF(qVersion(),"%d.%d.%d",&nV1App, &nV2App, &nV3App);
    11. int nV1DS = (BYTE)(QT_VERSION>>16);
    12. int nV2DS = (BYTE)(QT_VERSION>>8);
    13. // int nV3DS = (BYTE)QT_VERSION;
    14. if (nV1App < nV1DS || (nV1App == nV1DS && nV2App < nV2DS))
    15. return TWRC_FAILURE;
    16. }
    17. if (!pApp)
    18. {
    19. #ifdef TWNDS_OS_WIN
    20. _get_pgmptr(&pWinAppName);
    21. m_pUIThread = new UIThread(this, UIInfo);
    22. m_pUIThread->start();
    23. // Wait on the semaphore for the thread to start running
    24. // and that the thread has launched the dialog box.
    25. ScanXGUIEnabledSem.acquire(1);
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    The thread (m_pUIThread) creates the QApplication in its run method:

    Qt Code:
    1. void UIThread::run()
    2. {
    3. // Launch a QApplciation. (Windows only)
    4. // There are no command line arguments.
    5. int argc = 1;
    6. m_pQtApp = new QApplication(argc, &pWinAppName);
    7. if (m_pQtApp)
    8. {
    9. #ifdef TWNDS_OS_WIN
    10. // Create the dlg and make it visible.
    11. m_pDlg = new ScanXGUI(m_pUI, m_pChildWnd);
    12. if (m_pDlg)
    13. {
    14. pScanXDlg = m_pDlg;
    15. // Register to receive events.
    16. m_pQtApp->installEventFilter(m_pDlg);
    17. // Display the UI.
    18. m_pDlg->show();
    19. ScanXGUIEnabledSem.release(1);
    20. // Launch the message loop and do not return until thread closes.
    21. m_pQtApp->exec();
    22. // Ensure that the dialog box and class are destroyed.
    23. // done() causes the local event loop to finish.
    24. int CloseResult = 1;
    25. m_pDlg->done(CloseResult);
    26. delete m_pDlg;
    27. m_pDlg = NULL;
    28. }
    29. #endif
    30. delete m_pQtApp;
    31. }
    32. m_pQtApp = NULL;
    33. }
    To copy to clipboard, switch view to plain text mode 

  2. The following 2 users say thank you to astodolski for this useful post:


  3. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Using Qt 5, how do I create a user interface (modeless dialog box) in a Qt DLL?

    I believe that the move, frame, and repaint functionality is actually being provided by the window system (i.e. Windows), not Qt, but I could be wrong about that. It sounds to me as though your Qt event loop isn't being set up correctly or that the Qt events are being intercepted by the driver app before they can get to your dialog.

    You can probably check for an active event loop by implementing some kind of animation in your dialog (like a progress bar or a QTimer that changes something on timeout, for example) and seeing if it updates.

  4. #3
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Using Qt 5, how do I create a user interface (modeless dialog box) in a Qt DLL?

    Quote Originally Posted by d_stranz View Post
    I believe that the move, frame, and repaint functionality is actually being provided by the window system (i.e. Windows), not Qt, but I could be wrong about that. It sounds to me as though your Qt event loop isn't being set up correctly or that the Qt events are being intercepted by the driver app before they can get to your dialog.

    You can probably check for an active event loop by implementing some kind of animation in your dialog (like a progress bar or a QTimer that changes something on timeout, for example) and seeing if it updates.
    This all worked without issue in Qt 4.8.4. I am putting this out there in hopes that there are different considerations for what I am doing in Qt 5 as far as the GUI module is concerned.

Similar Threads

  1. madal dialog and modeless dialog problem
    By melody:p in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2012, 09:39
  2. QTimer and modeless dialog
    By artome in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2012, 17:35
  3. How to delete modeless dialog?
    By rajesh in forum Qt Programming
    Replies: 15
    Last Post: 16th June 2009, 13:19
  4. Modeless dialog disappearing
    By Raccoon29 in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2007, 12:38
  5. modeless dialog
    By mhoover in forum Newbie
    Replies: 2
    Last Post: 23rd March 2006, 23:56

Tags for this Thread

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.