Do I need to use a QWinHost object
-
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.
-
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 :)
-
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.
-
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.
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.
-
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.
@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)
-
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?
@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.
-
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!