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. Do I need to use a QWinHost object
Qt 6.12 LTS is out! See what's new in the release blog

Do I need to use a QWinHost object

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.7k Views 3 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
    #1

    I I have an application that starts out using QMfcApp then opens an MFC CDialog subclass. That hosts a QWinWidget with Qt "stuff" including a QStackedWidget.

    I wish to add an MFC CDialog subclass to a page of the QStackedWidget, do I need to add a QWinHost object to the page and then the CDialog as a child of the QWinHost or can I just add the CDialog to the stacked widget directly?

    (I don't want to go down the wrong route here).

    D.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You want to add a MFC dialog inside a Qt stacked widget inside a MFC window inside a Qt app... so basically you hate and want to punish yourself, right? :)

      Anyway, yes, whenever you want to put a window of one framework into a window of another you need to wrap it. To put Qt into MFC you wrap it into QWinWidget and when you want to put MFC into Qt you wrap it into QWinHost.

      Good luck, you'll need it :)

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

        I don't have a whole lot of choice when migrating a huge application from MFC to Qt. Only one piece at a time can be migrated.

        Looks like this is bad - message pump isn't being serviced properly when the StackedWidget is switched to the element that has the QWinHost/MFC Dlg.

        D.

        Chris KawaC JKSHJ 2 Replies Last reply
        0
        • PerdrixP Perdrix

          I don't have a whole lot of choice when migrating a huge application from MFC to Qt. Only one piece at a time can be migrated.

          Looks like this is bad - message pump isn't being serviced properly when the StackedWidget is switched to the element that has the QWinHost/MFC Dlg.

          D.

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I know the pain, been there. You'll get a lot of smaller and larger problems along that line. You'll see focus changing problems, input not getting through, confusion e.g. when you press something on MFC surface and then move mouse and release above Qt surface etc.

          My general approach was to port bottom up i.e. start with the most inner windows and build back, so that I only had to deal with one transition layer and just moved it up until everything was ported.

          I'm afraid there's no easy universal way to fix it. You'll have to dig into the wrapper code and do changes specific for your code. I had to do that until very little left from the original wrapper classes and then I just replaced them completely with custom message handling code.

          1 Reply Last reply
          4
          • PerdrixP Perdrix

            I don't have a whole lot of choice when migrating a huge application from MFC to Qt. Only one piece at a time can be migrated.

            Looks like this is bad - message pump isn't being serviced properly when the StackedWidget is switched to the element that has the QWinHost/MFC Dlg.

            D.

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

            @Perdrix said in Do I need to use a QWinHost object:

            Looks like this is bad - message pump isn't being serviced properly when the StackedWidget is switched to the element that has the QWinHost/MFC Dlg.

            Which version of Qt? QMfcApp's event hooks conflict with recent versions of Qt. Try getting rid of QMfcApp completely: https://bugreports.qt.io/browse/QTBUG-105719 (Qt can now use the MFC event loop directly)

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

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

              Ouch! I'm using Qt 5.15.2 and in general I am converting from the inside out.

              Can QMfcApp be discarded in this case? Or is this only on Qt6?

              JKSHJ 1 Reply Last reply
              0
              • PerdrixP Perdrix

                Ouch! I'm using Qt 5.15.2 and in general I am converting from the inside out.

                Can QMfcApp be discarded in this case? Or is this only on Qt6?

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

                @Perdrix said in Do I need to use a QWinHost object:

                Ouch! I'm using Qt 5.15.2 and in general I am converting from the inside out.

                Can QMfcApp be discarded in this case? Or is this only on Qt6?

                I believe Qt 5.15.2 isn't affected by the bug in my link (where the issue appeared between 6.2.3 -> 6.2.4)

                But at the same time, I did a quick test and Qt 5.15.2 was still functional after removing QMfcApp and using the code in the last comment. I can't say for sure if it will work in your case or not, with QWinHost and QWinWidget -- please try and see.

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

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

                  The QMfcApp is created in the CWinApp::InitInstance() mf as the first thing it does.

                  	QMfcApp::instance(this);
                  

                  the program has its own _tWinMain() that invokes AfxWinInit() to start MFC, and then runs InitInstance, and then invokes the main function of the program as a modal dialog using CDialog::DoModal().

                  It would appear that the Run() mf which contains:

                  	int result = QMfcApp::run(this);
                  	delete qApp;
                  	return result;
                  

                  is never actually invoked!

                  No - I didn't write this. Perhaps not quite the normal CWinApp application.

                  I'm not sure where to go from here!

                  1 Reply Last reply
                  0

                  • Login

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