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.
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?
-
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?
@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.
-
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
-
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.