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. waitforstarted returning true on a false command
Forum Update on Monday, May 27th 2025

waitforstarted returning true on a false command

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 628 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.
  • D Offline
    D Offline
    Dijkstra
    wrote on last edited by
    #1

    so i am starting a qprocess with a wrong command to check if my error handeling is correct my problem is waitforstarted function returns true and the process have a pid for a moment is that normal

    jsulmJ 1 Reply Last reply
    0
    • D Dijkstra

      so i am starting a qprocess with a wrong command to check if my error handeling is correct my problem is waitforstarted function returns true and the process have a pid for a moment is that normal

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dijkstra From the documentation: "Note: On some UNIX operating systems, this function may return true but the process may later report a QProcess::FailedToStart error."
      https://doc.qt.io/qt-5/qprocess.html#waitForStarted
      On what OS are you?

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

      D 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Dijkstra From the documentation: "Note: On some UNIX operating systems, this function may return true but the process may later report a QProcess::FailedToStart error."
        https://doc.qt.io/qt-5/qprocess.html#waitForStarted
        On what OS are you?

        D Offline
        D Offline
        Dijkstra
        wrote on last edited by
        #3

        @jsulm ubuntu

        connect(&plugin_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error)
            {
                qDebug() << "error running " <<getname()<<' '<< error << endl;
                if(processed_frames<get_frames())
                    emit(error_stop());
                return;
            });
            plugin_process.start("/bin/bash",QStringList() << "-c" << runCmd);
            bool started=plugin_process.waitForStarted();
            if(!started){
                std::cout<<"failed to start process"<<std::endl;
                emit(error_stop());
                return;
            }
        

        and this is what i am talking about this command will run a json file that doesnt exist my problem is that the error is not catched and the waitforstarted returns true

        jsulmJ JonBJ 2 Replies Last reply
        0
        • D Dijkstra

          @jsulm ubuntu

          connect(&plugin_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error)
              {
                  qDebug() << "error running " <<getname()<<' '<< error << endl;
                  if(processed_frames<get_frames())
                      emit(error_stop());
                  return;
              });
              plugin_process.start("/bin/bash",QStringList() << "-c" << runCmd);
              bool started=plugin_process.waitForStarted();
              if(!started){
                  std::cout<<"failed to start process"<<std::endl;
                  emit(error_stop());
                  return;
              }
          

          and this is what i am talking about this command will run a json file that doesnt exist my problem is that the error is not catched and the waitforstarted returns true

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Dijkstra You're starting bash, so why should that fail? That the application running in bash fails doesn't matter as your QProcess is starting bash...

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

          D 1 Reply Last reply
          2
          • D Dijkstra

            @jsulm ubuntu

            connect(&plugin_process, &QProcess::errorOccurred, [=](QProcess::ProcessError error)
                {
                    qDebug() << "error running " <<getname()<<' '<< error << endl;
                    if(processed_frames<get_frames())
                        emit(error_stop());
                    return;
                });
                plugin_process.start("/bin/bash",QStringList() << "-c" << runCmd);
                bool started=plugin_process.waitForStarted();
                if(!started){
                    std::cout<<"failed to start process"<<std::endl;
                    emit(error_stop());
                    return;
                }
            

            and this is what i am talking about this command will run a json file that doesnt exist my problem is that the error is not catched and the waitforstarted returns true

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

            @Dijkstra said in waitforstarted returning true on a false command:

            will run a json file

            [In addition to @jsulm, who is absolutely correct about the bash will run.] What do you mean by "run" a JSON file? JSON files are data, they don't "run" or "execute" anyway. Till we know what you actually mean it's hard to suggest a solutuon.

            D 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Dijkstra You're starting bash, so why should that fail? That the application running in bash fails doesn't matter as your QProcess is starting bash...

              D Offline
              D Offline
              Dijkstra
              wrote on last edited by
              #6

              @jsulm the process ends immediatly and the pid doesnt exist anymore but for a brief second their is a pid should i delay a second before checking the pid ? or what do you think should be done

              jsulmJ 1 Reply Last reply
              0
              • D Dijkstra

                @jsulm the process ends immediatly and the pid doesnt exist anymore but for a brief second their is a pid should i delay a second before checking the pid ? or what do you think should be done

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #7

                @Dijkstra There is no issue: it behaves as it should. You start bash and ask it to start a non-existent app. That means the process starts successfully (bash), but bash cannot execute what you asked it to execute, so it terminates. So, I don't know what you want to do now...

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

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Dijkstra said in waitforstarted returning true on a false command:

                  will run a json file

                  [In addition to @jsulm, who is absolutely correct about the bash will run.] What do you mean by "run" a JSON file? JSON files are data, they don't "run" or "execute" anyway. Till we know what you actually mean it's hard to suggest a solutuon.

                  D Offline
                  D Offline
                  Dijkstra
                  wrote on last edited by
                  #8

                  @JonB not a json file sorry i am running a certain exe file on my system that takes a json file

                  JonBJ 1 Reply Last reply
                  0
                  • D Dijkstra

                    @JonB not a json file sorry i am running a certain exe file on my system that takes a json file

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

                    @Dijkstra said in waitforstarted returning true on a false command:

                    @JonB not a json file sorry i am running a certain exe file on my system that takes a json file

                    OK, that's better! And as I imagined. The problem is: the lack of a data file for some executable is not going to cause any kind of QProcess::errorOccurred. The executable will start fine, then it will issue an error message and exit with a non-zero status (if it's well-behaved). So anything to do with QProcess::waitForStarted() is never going to tell you that. Hence why I asked. That is only going to be detectable by examining the exit code after completion.

                    [I assume by "this command will run a json file that doesnt exist " you meant the JSON file does not exist, not the command/executable does not exist. Whereas @jsulm is taking you to say the reverse. But who knows, since you don't make that clear.]

                    If you want help on this, you had better give the command you're actually running and explain what you want to trap/test for.....

                    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