Qt initialisation questions
-
The MFC application I am porting to Qt currently uses QWinWidget instances to host Qt stuff and has a winMain like:
int WINAPI _tWinMain(HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPTSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window )
which amongst many other things does:
- AfxOleInit()
- OleInitialize()
- starts GDI+
- AfxWinInit()
If I now turn the application inside out by deleting _tWinMain and
adding a regular main() that looks like this:int main(int argc, char* argv[]) { QApplication app(argc, argv); MyMainWindow mainWindow; mainWindow.show(); return app.exec(); }
which of the above things will already have been done for me by Qt initialisation and which will I have to place in the mainWindow initialisation code?
I tried looking at the source but failed to find the Windows initialisation plugin source code.
Thanks, David
-
The MFC application I am porting to Qt currently uses QWinWidget instances to host Qt stuff and has a winMain like:
int WINAPI _tWinMain(HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPTSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window )
which amongst many other things does:
- AfxOleInit()
- OleInitialize()
- starts GDI+
- AfxWinInit()
If I now turn the application inside out by deleting _tWinMain and
adding a regular main() that looks like this:int main(int argc, char* argv[]) { QApplication app(argc, argv); MyMainWindow mainWindow; mainWindow.show(); return app.exec(); }
which of the above things will already have been done for me by Qt initialisation and which will I have to place in the mainWindow initialisation code?
I tried looking at the source but failed to find the Windows initialisation plugin source code.
Thanks, David
@Perdrix said in Qt initialisation questions:
AfxWinInit()
My MFC knowledge is very very limited, but most of these function calls look like they are MFC specific and you wont need them in your Qt app later...
AfxWinInit This function is called by the MFC-supplied WinMain function, as part of the CWinApp initialization of a GUI-based application, to initialize MFC.
-
I DO need them right now as there are still a bunch of MFC things in the application - it's only partially converted to Qt.
D.
@Perdrix said in Qt initialisation questions:
MFC things in the application - it's only partially converted to Qt.
But you can only have one main window?! You have to decide, if your main app should be MFC or Qt. Running both event loops wont work
-
I DO need them right now as there are still a bunch of MFC things in the application - it's only partially converted to Qt.
D.
@Perdrix
Then other than looking through the sources/woboq yourself I don't see that someone who replies here would know, for sure, exactly which Windows calls (e.g.OleInitialize()
) Qt might or might not use. And don't forget it might not call these on startup, it might call them when required. Since Qt does not use MFC, it won't make MFC calls (e.g.AfxOleInit()
) though. -
@Perdrix said in Qt initialisation questions:
AfxWinInit()
My MFC knowledge is very very limited, but most of these function calls look like they are MFC specific and you wont need them in your Qt app later...
AfxWinInit This function is called by the MFC-supplied WinMain function, as part of the CWinApp initialization of a GUI-based application, to initialize MFC.
-
@Perdrix
Then other than looking through the sources/woboq yourself I don't see that someone who replies here would know, for sure, exactly which Windows calls (e.g.OleInitialize()
) Qt might or might not use. And don't forget it might not call these on startup, it might call them when required. Since Qt does not use MFC, it won't make MFC calls (e.g.AfxOleInit()
) though. -
@Perdrix said in Qt initialisation questions:
MFC things in the application - it's only partially converted to Qt.
But you can only have one main window?! You have to decide, if your main app should be MFC or Qt. Running both event loops wont work
-
@JonB said in Qt initialisation questions:
sources/woboq
I can't find a directory by that name ... I someone can point me to relevant source code I'm happy to read it myself
@Perdrix said in Qt initialisation questions:
I can't find a directory by that name
@JonB means to look in Qt source code or use Woboq to do so: https://codebrowser.dev/qt6/
-
@Pl45m4 said in Qt initialisation questions:
MFC-supplied WinMain
You mean the template code that is put into your project when you create an MFC project in VS2019 (e.g.). Yes, I KNOW that - as that code is what's in my WinMain.
D.
@Perdrix said in Qt initialisation questions:
You mean the template code that is put into your project when you create an MFC project in VS2019
The part I quoted is from Microsoft Docs.
If you want to port your app to Qt, it wont make sense to use them. And if you need them for whatever reason, you need to call them. I doubt that Qt will call functions to init MFC windows in its QApp initialization.
AFAIK there are things like
QMfcApp
and Qt2MFC migration tools but I dont know if they are still valid. Some of them seem to be quite old.