Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Confused about QMfcApp
Qt 6.12 LTS is out! See what's new in the release blog

Confused about QMfcApp

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by Perdrix
    #1

    I've seen recent replies to some of my questions saying the QMfcApp is not compatible with current releases of Qt (does that include 5.15.2)? My understanding was that the whole point of QMfcApp was to merge the event handling for QApplication and CWinApp.

    If that's removed from the picture how do I create and use non-modal CDialog objects if I simply create a QApplication object and a QMainWindow object in my main(). Do I still need to create and manage a CWinApp object in parallel to the QApplication instance. I suspect that's a yes?

    Is that simply achieved by using QWinHost?

    e.g.

    	winHost = new QWinHost(stackedWidget);
    	winHost->setObjectName("winHost");
    	stackedWidget->addWidget(winHost);
    
    	processingDlg.Create(IDD_PROCESSING, this);    // CDialog sub-class
    
    	winHost->setWindow(processingDlg.m_hWnd);
    

    or is there more to it than that? If so what more do I need to know and do?

    JKSHJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      I've seen recent replies to some of my questions saying the QMfcApp is not compatible with current releases of Qt (does that include 5.15.2)? My understanding was that the whole point of QMfcApp was to merge the event handling for QApplication and CWinApp.

      If that's removed from the picture how do I create and use non-modal CDialog objects if I simply create a QApplication object and a QMainWindow object in my main(). Do I still need to create and manage a CWinApp object in parallel to the QApplication instance. I suspect that's a yes?

      Is that simply achieved by using QWinHost?

      e.g.

      	winHost = new QWinHost(stackedWidget);
      	winHost->setObjectName("winHost");
      	stackedWidget->addWidget(winHost);
      
      	processingDlg.Create(IDD_PROCESSING, this);    // CDialog sub-class
      
      	winHost->setWindow(processingDlg.m_hWnd);
      

      or is there more to it than that? If so what more do I need to know and do?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Perdrix said in Confused about QMfcApp:

      I've seen recent replies to some of my questions saying the QMfcApp is not compatible with current releases of Qt (does that include 5.15.2)? My understanding was that the whole point of QMfcApp was to merge the event handling for QApplication and CWinApp.

      QtWinMigrate was designed in the era of Qt 3.

      Even as early as Qt 4, parts of QMfcApp had become obsolete. As of Qt 5, there is no longer a need to "merge" event handling. If you have an native MFC event loop, Qt can use it. You still need to create a QApplication to use Qt widgets, but you don't need to create QMfcApp or run QApplication::exec().

      However, I don't know about the other way round: I don't know if MFC classes can use the Qt event loop directly (but my gut feeling says they can).

      If that's removed from the picture how do I create and use non-modal CDialog objects if I simply create a QApplication object and a QMainWindow object in my main(). Do I still need to create and manage a CWinApp object in parallel to the QApplication instance. I suspect that's a yes?

      I don't know the answer to this as I don't have in-depth knowledge of MFC.

      But the purpose of QtWinMigrate was to help convert MFC projects into Qt projects (meaning you already have an MFC GUI and an MFC event loop). The summary of what I know is this: If you have an existing MFC application, you can add Qt Widgets to it without creating QMfcApp.

      Is that simply achieved by using QWinHost?

      e.g.

      	winHost = new QWinHost(stackedWidget);
      	winHost->setObjectName("winHost");
      	stackedWidget->addWidget(winHost);
      
      	processingDlg.Create(IDD_PROCESSING, this);    // CDialog sub-class
      
      	winHost->setWindow(processingDlg.m_hWnd);
      

      or is there more to it than that? If so what more do I need to know and do?

      Please try your sample code and let us know the outcome.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      4
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Well after some "trials and tribulations" I have turned the application "inside-out" so the first thing that's created is a QMainWindow.

        In the ctor for that I wrote:

        	winHost = new QWinHost(stackedWidget);
        	winHost->setObjectName("winHost");
        	stackedWidget->addWidget(winHost);
        
        	ZTRACE_RUNTIME("Creating Processing Panel");
        	processingDlg.Create(IDD_PROCESSING);
        
        
        	HWND hwnd{ processingDlg.GetSafeHwnd() };
        	Q_ASSERT(NULL != hwnd);
        	winHost->setWindow(hwnd);
        
        

        and of course (Yes, you guessed it) the HWND for processingDlg is NULL.

        How to get the CDialog control initialised far enough to get an HWND assigned?

        David

        1 Reply Last reply
        0
        • PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #4

          Problem was that the message pump wasn't running when the ctor was invoked (just prior to qApp->exec())

          I solved that by moving the code from the QMainWindow ctor, to an mf called onInitialise() which I invoke from showEvent():

          void DeepSkyStacker::showEvent(QShowEvent* event)
          {
          	if (!event->spontaneous())
          	{
          		if (!initialised)
          		{
          			initialised = true;
          			onInitialise();
          		}
          	}
          	// Invoke base class showEvent()
          	return Inherited::showEvent(event);
          }
          

          D.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved