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. problem in run external program with QProcess
Qt 6.11 is out! See what's new in the release blog

problem in run external program with QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 3 Posters 2.0k 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.
  • S saeid0034

    @Christian-Ehrlicher i know because for now code itself doesnt work good

    QObject::connect(BigPAKC, &QProcess::errorOccurred, [] (QProcess::ProcessError error) {
                                qDebug() << "Error: " << error;
                            });
    QObject::connect(BigPAKC, &QProcess::started, [] () -> void {
                                qDebug() << "Process has started!";
                            });
    QObject::connect(BigPAKC, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
                                             [=](int exitCode, QProcess::ExitStatus exitStatus){
                                qDebug() << exitCode << exitStatus;
                            });
    
    QObject::connect(BigPAKC, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), &QObject::deleteLater);
    
    

    @JonB as i said program run without problem and do the job (also im sure antivirus dont block process) my only problem is signal doesn't emit

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

    @saeid0034
    Show your code now. Don't mix waitFor...()s with signals.

    S 1 Reply Last reply
    3
    • JonBJ JonB

      @saeid0034
      Show your code now. Don't mix waitFor...()s with signals.

      S Offline
      S Offline
      saeid0034
      wrote on last edited by
      #9

      @JonB thanks, so this time i remove waitFor...() from my code and only use signal and slot, this time Finished Signal emited, with 0 QProcess::NormalExit, but i get unknow error too

      JonBJ 1 Reply Last reply
      0
      • S saeid0034

        @JonB thanks, so this time i remove waitFor...() from my code and only use signal and slot, this time Finished Signal emited, with 0 QProcess::NormalExit, but i get unknow error too

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

        @saeid0034
        Better :) Don't use waitFor...()s again :) "unknown error" can also maybe if no error. Put in slots on readyReadStandardOutput()/Error() now?

        S 1 Reply Last reply
        0
        • JonBJ JonB

          @saeid0034
          Better :) Don't use waitFor...()s again :) "unknown error" can also maybe if no error. Put in slots on readyReadStandardOutput()/Error() now?

          S Offline
          S Offline
          saeid0034
          wrote on last edited by
          #11

          @JonB both give me empty output

          BigPAKC->readAllStandardOutput();
          BigPAKC->readAllStandardError();
          
          JonBJ 1 Reply Last reply
          0
          • S saeid0034

            @JonB both give me empty output

            BigPAKC->readAllStandardOutput();
            BigPAKC->readAllStandardError();
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #12

            @saeid0034
            I already suggested you try cmd /c dir but you would not. So far as I can see everything is working fine, you have not shown there is any actual problem.

            You don't show code, so I can only hope your code is correctly in slots set up in the right places.

            S 1 Reply Last reply
            0
            • JonBJ JonB

              @saeid0034
              I already suggested you try cmd /c dir but you would not. So far as I can see everything is working fine, you have not shown there is any actual problem.

              You don't show code, so I can only hope your code is correctly in slots set up in the right places.

              S Offline
              S Offline
              saeid0034
              wrote on last edited by
              #13

              @JonB thanks, yes code seems working
              i send my code above, it all code i use for qprocess.
              and about cmd /c dir, what i'm supposed to do with it?

              JonBJ 1 Reply Last reply
              0
              • S saeid0034

                @JonB thanks, yes code seems working
                i send my code above, it all code i use for qprocess.
                and about cmd /c dir, what i'm supposed to do with it?

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

                @saeid0034 said in problem in run external program with QProcess:

                thanks, yes code seems working

                If you mean everything is working then there is no issue,

                i send my code above, it all code i use for qprocess.

                You have shown fragments of code, which you say you have added to and deleted from. I do not know what your code looks like now.

                and about cmd /c dir, what i'm supposed to do with it?

                You were supposed to replace your process start()ing code by:
                BigPAKC->start("cmd", QStringList() << "/c" << "dir");

                EDIT
                OMG, I have only just noticed in your code:

                			if (!BigPAKC->waitForStarted())
                				qDebug() << "started";
                	         
                			if (!BigPAKC->waitForFinished(-1))
                				qDebug() << "Finished";
                

                I did not see the !s. So you print nothing when all is well.... So what is your problem if it all worked fine from the outset?

                S 1 Reply Last reply
                1
                • JonBJ JonB

                  @saeid0034 said in problem in run external program with QProcess:

                  thanks, yes code seems working

                  If you mean everything is working then there is no issue,

                  i send my code above, it all code i use for qprocess.

                  You have shown fragments of code, which you say you have added to and deleted from. I do not know what your code looks like now.

                  and about cmd /c dir, what i'm supposed to do with it?

                  You were supposed to replace your process start()ing code by:
                  BigPAKC->start("cmd", QStringList() << "/c" << "dir");

                  EDIT
                  OMG, I have only just noticed in your code:

                  			if (!BigPAKC->waitForStarted())
                  				qDebug() << "started";
                  	         
                  			if (!BigPAKC->waitForFinished(-1))
                  				qDebug() << "Finished";
                  

                  I did not see the !s. So you print nothing when all is well.... So what is your problem if it all worked fine from the outset?

                  S Offline
                  S Offline
                  saeid0034
                  wrote on last edited by
                  #15

                  @JonB Im worried about Unknown error but as you say its possible its mean no error

                  JonBJ 1 Reply Last reply
                  0
                  • S saeid0034

                    @JonB Im worried about Unknown error but as you say its possible its mean no error

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

                    @saeid0034

                    QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().

                    No error occurred in your code. This has been a long discussion for that situation.

                    Why in the world did you write

                    			if (!BigPAKC->waitForStarted())
                    				qDebug() << "started";
                    

                    instead of if (BigPAKC->waitForStarted()) ?

                    S 1 Reply Last reply
                    1
                    • JonBJ JonB

                      @saeid0034

                      QProcess::UnknownError 5 An unknown error occurred. This is the default return value of error().

                      No error occurred in your code. This has been a long discussion for that situation.

                      Why in the world did you write

                      			if (!BigPAKC->waitForStarted())
                      				qDebug() << "started";
                      

                      instead of if (BigPAKC->waitForStarted()) ?

                      S Offline
                      S Offline
                      saeid0034
                      wrote on last edited by
                      #17

                      @JonB because i see example on https://doc.qt.io/qt-5/qprocess.html

                      JonBJ 1 Reply Last reply
                      0
                      • S saeid0034

                        @JonB because i see example on https://doc.qt.io/qt-5/qprocess.html

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

                        @saeid0034
                        Your code:

                        			if (!BigPAKC->waitForStarted())
                        				qDebug() << "started";
                        	         
                        			if (!BigPAKC->waitForFinished(-1))
                        				qDebug() << "Finished";
                        

                        Your description of what was wrong:

                        but my problem is both waitForStarted and waitForFinished never work, i mean waitForFinished doesnt wait for process to end and print Finished at start,

                        Why do you expect a successful waitForFinished() to print Finished here? Do you understand that with your use of ! it won't say anything when everything succeeds as it should?

                        S 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @saeid0034
                          Your code:

                          			if (!BigPAKC->waitForStarted())
                          				qDebug() << "started";
                          	         
                          			if (!BigPAKC->waitForFinished(-1))
                          				qDebug() << "Finished";
                          

                          Your description of what was wrong:

                          but my problem is both waitForStarted and waitForFinished never work, i mean waitForFinished doesnt wait for process to end and print Finished at start,

                          Why do you expect a successful waitForFinished() to print Finished here? Do you understand that with your use of ! it won't say anything when everything succeeds as it should?

                          S Offline
                          S Offline
                          saeid0034
                          wrote on last edited by
                          #19

                          @JonB sorry about that, i only see unknow error -_-
                          thanks about help

                          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