Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt initialisation questions
Forum Updated to NodeBB v4.3 + New Features

Qt initialisation questions

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 621 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

    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

    Pl45m4P 1 Reply Last reply
    0
    • PerdrixP Perdrix

      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

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

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

      (from: https://docs.microsoft.com/en-us/cpp/mfc/reference/application-information-and-management?view=msvc-170#afxwininit)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

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

        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.

        Pl45m4P JonBJ 2 Replies Last reply
        0
        • PerdrixP Perdrix

          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.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @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


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          PerdrixP 1 Reply Last reply
          0
          • PerdrixP Perdrix

            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.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

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

            PerdrixP 1 Reply Last reply
            0
            • Pl45m4P Pl45m4

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

              (from: https://docs.microsoft.com/en-us/cpp/mfc/reference/application-information-and-management?view=msvc-170#afxwininit)

              PerdrixP Offline
              PerdrixP Offline
              Perdrix
              wrote on last edited by
              #6

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

              Pl45m4P 1 Reply Last reply
              0
              • JonBJ JonB

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

                PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by
                #7

                @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

                jsulmJ 1 Reply Last reply
                0
                • Pl45m4P Pl45m4

                  @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

                  PerdrixP Offline
                  PerdrixP Offline
                  Perdrix
                  wrote on last edited by
                  #8

                  @Pl45m4 That's what QWinHost is for. ...

                  1 Reply Last reply
                  0
                  • PerdrixP Perdrix

                    @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

                    jsulmJ Online
                    jsulmJ Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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/

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • PerdrixP Perdrix

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

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #10

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


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      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 Extensions
                      • Unsolved