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. Visual Studio Code in parallel with QtCode
Forum Update on Monday, May 27th 2025

Visual Studio Code in parallel with QtCode

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.3k Views
  • 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.
  • J Offline
    J Offline
    Josz
    wrote on last edited by Josz
    #1

    Hi Comunity,
    I have an old app written in C++ using Visual Studio enviroment. I have to replace its GUI, so I have developed an small GUI in Qt.
    I have a point in that old program where the old GUI is created. I thought that just in that point should I the Qt gui in paralel start and the rest will be send signals to interface.

    I readed the next post for the threads https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

    In First place, I'm trying to write an small program where the MainWindow will moved into a new thread and after, furthermore code (a cout << "hello" << endl; for example) will executed.

    To follow the method in above link showed, I'm trying to build an object with the necessary calls to create the main window, thinking in moving that object into a new thread.

    here is the code:
    (main.cpp)

    #include "mainwindow.h"
    #include <QApplication>
    #include <QObject>
    
    class GuiApp : public QObject
    {
        Q_OBJECT
    
    public:
        explicit GuiApp(int argc, char *argv[]);
        ~GuiApp();
        int returnExec();
    
    private:
        QApplication *a;//QApplication a(argc, argv);
    };
    
    GuiApp::GuiApp(int argc, char *argv[])
    {
       a = new QApplication(argc, argv);
        MainWindow w;
        w.show();
        returnExec();
    }
    
    GuiApp::~GuiApp()
    {
        delete a;
    }
    
    int GuiApp::returnExec()
    {
        return a->exec();
    }
    
    //***********************************************
    //***********************************************
    int main(int argc, char *argv[])
    {
    
        GuiApp gApp(argc, argv);
        /*I intend write here the sentences to move gApp to the new thread
         *
         *
         */
    
        //The code after this point should be executed in parallel 
        cout  << "hello" << endl;
    }
    
    

    That's my idea, but I get the following linkage errors

    main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall GuiApp::metaObject(void)const " (?metaObject@GuiApp@@UBEPBUQMetaObject@@XZ)
    main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall GuiApp::qt_metacast(char const *)" (?qt_metacast@GuiApp@@UAEPAXPBD@Z)
    main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall GuiApp::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@GuiApp@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
    debug\parallel_test.exe : fatal error LNK1120: 3 unresolved externals
    

    Is this the right way? Please Could anybody help me or to fix the linker errors (case that the right way ist) or show me the right form to make this?

    Any help oder suggestion will be good welcomed
    Thanks in advance.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You should create your Visual Studio solution with the help of qmake and a .pro - file: http://doc.qt.io/qt-5/qmake-platform-notes.html and http://doc.qt.io/qt-5/qmake-tutorial.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        You should create your Visual Studio solution with the help of qmake and a .pro - file: http://doc.qt.io/qt-5/qmake-platform-notes.html and http://doc.qt.io/qt-5/qmake-tutorial.html

        J Offline
        J Offline
        Josz
        wrote on last edited by Josz
        #3

        @Christian-Ehrlicher Thank you very much, that's a point to begin with the import process of the visual studio project. Any help with the paralel execution from the code?

        thanks in advance

        mrjjM 1 Reply Last reply
        0
        • J Josz

          @Christian-Ehrlicher Thank you very much, that's a point to begin with the import process of the visual studio project. Any help with the paralel execution from the code?

          thanks in advance

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Josz
          Hi
          you can try ( worked for me on win 10)
          https://forum.qt.io/topic/67285/ui-application-as-thread-cpu-load-almost-100/11
          all credits to mr kshegunov

          J 2 Replies Last reply
          3
          • mrjjM mrjj

            @Josz
            Hi
            you can try ( worked for me on win 10)
            https://forum.qt.io/topic/67285/ui-application-as-thread-cpu-load-almost-100/11
            all credits to mr kshegunov

            J Offline
            J Offline
            Josz
            wrote on last edited by Josz
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • mrjjM mrjj

              @Josz
              Hi
              you can try ( worked for me on win 10)
              https://forum.qt.io/topic/67285/ui-application-as-thread-cpu-load-almost-100/11
              all credits to mr kshegunov

              J Offline
              J Offline
              Josz
              wrote on last edited by Josz
              #6

              @mrjj Sadly Did not work :_(. The loop run only when I close the MainWindow.
              I'm on Windows 7 with msvsc2015 32 bits and Qt 5.11.2. In my .pro I have CONFIG += c++11. Replacing for c++14 is the same

              here is my code

              #include "mainwindow.h"
              #include <QApplication>
              #include <thread>
              #include <iostream>
              
              using namespace std;
              
              void guiLoader(int argc, char *argv[]){
                  QApplication a(argc, argv);
                  MainWindow w;
                  w.show();
              
                  //return a.exec();
                  QApplication::exec(); 
              }
              
              void loop(){
                      while(1)
                          cerr << "Parallel hello World" << endl;
              }
              
              int main(int argc, char *argv[])
              {
                  thread guiLoaderThread(guiLoader, argc, argv);
                  guiLoaderThread.join();
                  loop();
              }
              
              
              1 Reply Last reply
              0
              • J Offline
                J Offline
                Josz
                wrote on last edited by Josz
                #7

                Didn't work because the position of "guiLoaderThread.join();". This sentence must be placed at the end of the code that you want to execute. Is like "The code will run until here"

                The next version work fine

                #include "mainwindow.h"
                #include <QApplication>
                #include <thread>
                #include <iostream>
                
                using namespace std;
                
                void guiLoader(int argc, char *argv[]){
                    QApplication a(argc, argv);
                    MainWindow w;
                    w.show();
                
                    //return a.exec();
                    QApplication::exec();
                }
                
                void loop(){
                        for(int i = 0; i < 100; i++)
                            cerr << "helloworld parallel" << endl;
                }
                
                int main(int argc, char *argv[])
                {
                    thread guiLoaderThread(guiLoader, argc, argv);
                    loop();
                    cerr << "last line to be executed" << endl;
                    guiLoaderThread.join();
                
                    return 11;
                }
                
                
                1 Reply Last reply
                1

                • Login

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