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. QProcess not able (?) to start a Qt application
Forum Update on Monday, May 27th 2025

QProcess not able (?) to start a Qt application

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 1.6k 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.
  • gbettegaG Offline
    gbettegaG Offline
    gbettega
    wrote on last edited by
    #1

    Hi Forum
    I have a very large Qt application, say LA, which at some point needs to start a smaller Qt application, say SA, which has been built separately (essentially a widget for data analysis, which I don't want to compile within the large code).
    I used, as in many other part of LA, the QProcess paradigma (create a QProcess on the heap, define program, define list of arguments, call start with wait for finished). This is not working for the Qt SA.
    Note:

    1. The SA.exe has it's own directory with the deployment libraries (so it can be launched with a d-click, or by the cmd command line).
    2. in LA QProcess has been successfully used for non-Qt programs

    Any idea?
    Thanks in advance
    Giovanni

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • gbettegaG gbettega

      Hi Forum
      I have a very large Qt application, say LA, which at some point needs to start a smaller Qt application, say SA, which has been built separately (essentially a widget for data analysis, which I don't want to compile within the large code).
      I used, as in many other part of LA, the QProcess paradigma (create a QProcess on the heap, define program, define list of arguments, call start with wait for finished). This is not working for the Qt SA.
      Note:

      1. The SA.exe has it's own directory with the deployment libraries (so it can be launched with a d-click, or by the cmd command line).
      2. in LA QProcess has been successfully used for non-Qt programs

      Any idea?
      Thanks in advance
      Giovanni

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @gbettega
      as I'm using Process to start other Qt-based applications, I can say it works fine.

      Whats your OS and QtVersion ?
      Can you show us your QProcess code?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • gbettegaG gbettega

        Hi Forum
        I have a very large Qt application, say LA, which at some point needs to start a smaller Qt application, say SA, which has been built separately (essentially a widget for data analysis, which I don't want to compile within the large code).
        I used, as in many other part of LA, the QProcess paradigma (create a QProcess on the heap, define program, define list of arguments, call start with wait for finished). This is not working for the Qt SA.
        Note:

        1. The SA.exe has it's own directory with the deployment libraries (so it can be launched with a d-click, or by the cmd command line).
        2. in LA QProcess has been successfully used for non-Qt programs

        Any idea?
        Thanks in advance
        Giovanni

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @gbettega
        As @J-Hilk says we need to see code.
        Your code should be checking for errors (inc. any exit code) and importantly should be capturing stderr at launch time so that we can see any OS error message. That might be telling you what you need to know.
        Does SA.exe work if its current/working directory is not where the .exe is?

        gbettegaG 1 Reply Last reply
        0
        • gbettegaG Offline
          gbettegaG Offline
          gbettega
          wrote on last edited by
          #4

          Hello,
          Windows 10, Qt 5.8.0 MSVC 2015

          The application I'm trying to start is TimeStepBuilder.exe

          QProcess *shellP = new QProcess(this);
          QString program = QString::fromLatin1(std::getenv("TIMESTEPBUILDER_PATH"))+"\\TimeStepBuilder.exe";
          
          cout<<"____"<<program.toStdString()<<"____"<<endl;
              system("D:\\Work\\Qt\\TimeStepBuilder\\TimeStepBuilderBuild\\release\\TimeStepBuilder.exe");
          
          QStringList arguments;
          arguments<<tools::getWorkingDir()<<timeHistoryFileLoc;
              
          shellP->setProgram(program);
          shellP->setArguments(arguments);
          shellP->start();
          shellP->waitForFinished(-1);
          int exitCode = shellP->exitCode();
              
          cout<<"___exit code: "<<exitCode<<"____"<<endl;
          ...
          

          Exit code = 0 if waitForFinished(-1) is commented
          Exit code = -1073741511 if not

          I cannot understand at all...

          The picture shows the TimeStepBuilder.exe application
          Thanks
          Giovanni

          tsb.png

          JonBJ 1 Reply Last reply
          0
          • gbettegaG gbettega

            Hello,
            Windows 10, Qt 5.8.0 MSVC 2015

            The application I'm trying to start is TimeStepBuilder.exe

            QProcess *shellP = new QProcess(this);
            QString program = QString::fromLatin1(std::getenv("TIMESTEPBUILDER_PATH"))+"\\TimeStepBuilder.exe";
            
            cout<<"____"<<program.toStdString()<<"____"<<endl;
                system("D:\\Work\\Qt\\TimeStepBuilder\\TimeStepBuilderBuild\\release\\TimeStepBuilder.exe");
            
            QStringList arguments;
            arguments<<tools::getWorkingDir()<<timeHistoryFileLoc;
                
            shellP->setProgram(program);
            shellP->setArguments(arguments);
            shellP->start();
            shellP->waitForFinished(-1);
            int exitCode = shellP->exitCode();
                
            cout<<"___exit code: "<<exitCode<<"____"<<endl;
            ...
            

            Exit code = 0 if waitForFinished(-1) is commented
            Exit code = -1073741511 if not

            I cannot understand at all...

            The picture shows the TimeStepBuilder.exe application
            Thanks
            Giovanni

            tsb.png

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

            @gbettega
            You really need to use the signals/slots to check for errors, and capture stderr to see if an error is being reported, if you expect to sort this out (should be in production code anyway, what do you expect end user to do if errors are being reported and nothing is looking at them?)

            Why does your code already run the program once via system()? Is there an issue about having 2 instances running?

            1 Reply Last reply
            3
            • JonBJ JonB

              @gbettega
              As @J-Hilk says we need to see code.
              Your code should be checking for errors (inc. any exit code) and importantly should be capturing stderr at launch time so that we can see any OS error message. That might be telling you what you need to know.
              Does SA.exe work if its current/working directory is not where the .exe is?

              gbettegaG Offline
              gbettegaG Offline
              gbettega
              wrote on last edited by
              #6

              Sorry, this is the right code.
              The SA.exe file does not start if called from outside its directory (no env variable has been set for it):
              indeed the program string contains the absolute path, retrieved from an user env variable.
              TimeStepBuilder.exe (SA.exe) starts normally when launched from the windows shell.
              Regards
              Giovanni

                  const QString &timeHistoryFileLoc = curNode->getPropertyValue<QString>("Time history file");
              
                  QProcess *shellP = new QProcess(this);
                  QString program = QString::fromLatin1(std::getenv("TIMESTEPBUILDER_PATH"))+"\\TimeStepBuilder.exe";
                  cout<<"____"<<program.toStdString()<<"____"<<endl;
                  QStringList arguments;
                  arguments<<tools::getWorkingDir()<<timeHistoryFileLoc;
              
                  shellP->setProgram(program);
                  shellP->setArguments(arguments);
                  shellP->start();
                  shellP->waitForFinished(-1);
                  int exitCode = shellP->exitCode();
              
                  cout<<"___exit code: "<<exitCode<<"____"<<endl;
              
              
              JonBJ 1 Reply Last reply
              0
              • gbettegaG gbettega

                Sorry, this is the right code.
                The SA.exe file does not start if called from outside its directory (no env variable has been set for it):
                indeed the program string contains the absolute path, retrieved from an user env variable.
                TimeStepBuilder.exe (SA.exe) starts normally when launched from the windows shell.
                Regards
                Giovanni

                    const QString &timeHistoryFileLoc = curNode->getPropertyValue<QString>("Time history file");
                
                    QProcess *shellP = new QProcess(this);
                    QString program = QString::fromLatin1(std::getenv("TIMESTEPBUILDER_PATH"))+"\\TimeStepBuilder.exe";
                    cout<<"____"<<program.toStdString()<<"____"<<endl;
                    QStringList arguments;
                    arguments<<tools::getWorkingDir()<<timeHistoryFileLoc;
                
                    shellP->setProgram(program);
                    shellP->setArguments(arguments);
                    shellP->start();
                    shellP->waitForFinished(-1);
                    int exitCode = shellP->exitCode();
                
                    cout<<"___exit code: "<<exitCode<<"____"<<endl;
                
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @gbettega

                @JonB wrote:

                You really need to use the signals/slots to check for errors, and capture stderr to see if an error is being reported, if you expect to sort this out (should be in production code anyway, what do you expect end user to do if errors are being reported and nothing is looking at them?)

                No point ignoring this.

                1 Reply Last reply
                0
                • gbettegaG Offline
                  gbettegaG Offline
                  gbettega
                  wrote on last edited by
                  #8

                  Hello
                  I do not need points. This is not Champions League. Just for info, I made

                  connect(shellP,SIGNAL(readyReadStandardError()),this,SLOT(captureErr()));

                  where the slot accesses the shellP (made public) write on stderr, and immediately exit(<error code>).
                  No error is detected
                  Regards
                  Giovanni

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    Hi
                    try
                    shellP->setWorkingDirectory( std::getenv("TIMESTEPBUILDER_PATH") );

                    It might be that the Qt program cannot find its support DLLs when called via QProcess.

                    1 Reply Last reply
                    1
                    • gbettegaG Offline
                      gbettegaG Offline
                      gbettega
                      wrote on last edited by
                      #10

                      Thank you very much mrjj for your suggestion. I discovered it is something related to your observation.
                      Actually, at the moment , the LargeApplication is launched from the QtCreator, so the .exe files loads the .dll from the Qt directory. There is not a deployment for LA.

                      Instead, the SmallApplication SA.exe loads the Qt dll from its own distribution directory, since it exists as a deployment.

                      When launching the Large App from Creator and then using the Qt process for launching in turn the SmallApp some .dll conflict arise (actually more than one).

                      Indeed I solved by:

                      1. copying the SmallApp exe into the build directory of the Large App one
                      2. building the depolyment of SmallApp in that dir
                      3. deleting unecessary .dll (which avoid the main app from starting from the Qt Creator)

                      and it works.
                      QProcess.PNG Regards

                      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