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::issues
QtWS25 Last Chance

QProcess::issues

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 3.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.
  • QT_QT_QTQ Offline
    QT_QT_QTQ Offline
    QT_QT_QT
    wrote on last edited by
    #1

    HI, i keep geeting this error: QProcess:Destroyed, while process("cmd" )is still running. Here is my codes:

    QProcess procA();
       /procA.setWorkingDirectory("C:\\Users\\USER\\Desktop\\FileA\\FileB");
        procA.start("cmd",QStringList());
        procA.start("cmd");
        if(!procA.waitForStarted()){
            return ;
        }
        procA.write("mkdir newFolder");
        QMessageBox::information(this,tr("Completed"),tr("completed"));
        procA.closeWriteChannel();
        QByteArray outputA;
        if(procA.waitForReadyRead()){
            outputA += procA.readAll();
        }
        qDebug() << outputA;//your code here
    

    I dont understand why keep getting that error message . I dont really understand what is going on.

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I guess this code is located in a function/method, right?
      The problem is: the "cmd" command is still running after creating the directory and as soon as the function/method is finished procA goes out of scope and is destroyed. That's why you get this message. You should first exit cmd and then destroy procA.

      Why do you use QProcess and cmd to create directories? You can use http://doc.qt.io/qt-5.6/qdir.html#mkdir

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

      QT_QT_QTQ 1 Reply Last reply
      0
      • jsulmJ jsulm

        I guess this code is located in a function/method, right?
        The problem is: the "cmd" command is still running after creating the directory and as soon as the function/method is finished procA goes out of scope and is destroyed. That's why you get this message. You should first exit cmd and then destroy procA.

        Why do you use QProcess and cmd to create directories? You can use http://doc.qt.io/qt-5.6/qdir.html#mkdir

        QT_QT_QTQ Offline
        QT_QT_QTQ Offline
        QT_QT_QT
        wrote on last edited by QT_QT_QT
        #3

        @jsulm

        Hi,

        Thanks for the feedback!Yes,Its located in a function. Regarding to "mkdir newFolder" , this is just a string that i wish to parse into cmd. The string could be anything . The idea is parse some string in to cmd, and the let the cmd do the rest of work.

        You also said "You should first exit cmd and then destroy procA" . Can you provide me an example for this . Thanks

        1 Reply Last reply
        0
        • jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Just pass "exit" command to the process like you did for "mkdir ..." and then call http://doc.qt.io/qt-5/qprocess.html#waitForFinished

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

          QT_QT_QTQ 1 Reply Last reply
          0
          • jsulmJ jsulm

            Just pass "exit" command to the process like you did for "mkdir ..." and then call http://doc.qt.io/qt-5/qprocess.html#waitForFinished

            QT_QT_QTQ Offline
            QT_QT_QTQ Offline
            QT_QT_QT
            wrote on last edited by QT_QT_QT
            #5

            @jsulm

                 QProcess procA();
               procA.setWorkingDirectory("C:\\Users\\USER\\Desktop\\FileA\\FileB");
                procA.start("cmd",QStringList());
                
                if(!procA.waitForStarted()){
                    return ;
                }
               ** procA.write("exit");
            procA.waitForFinished();**
                QMessageBox::information(this,tr("Completed"),tr("completed"));
                procA.closeWriteChannel();
                QByteArray outputA;
                if(procA.waitForReadyRead()){
                    outputA += procA.readAll();
                }
            

            Something like this?

            1 Reply Last reply
            0
            • jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              More like:

              QProcess procA();
              /procA.setWorkingDirectory("C:\\Users\\USER\\Desktop\\FileA\\FileB");
              procA.start("cmd",QStringList());
              procA.start("cmd");
              if(!procA.waitForStarted()){
                  return ;
              }
              procA.write("mkdir newFolder");
              QMessageBox::information(this,tr("Completed"),tr("completed"));
              procA.closeWriteChannel();
              QByteArray outputA;
              if(procA.waitForReadyRead()){
                  outputA += procA.readAll();
              }
              qDebug() << outputA;//your code here
              procA.write("exit");
              procA.waitForFinished();
              

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

              QT_QT_QTQ 2 Replies Last reply
              1
              • jsulmJ jsulm

                More like:

                QProcess procA();
                /procA.setWorkingDirectory("C:\\Users\\USER\\Desktop\\FileA\\FileB");
                procA.start("cmd",QStringList());
                procA.start("cmd");
                if(!procA.waitForStarted()){
                    return ;
                }
                procA.write("mkdir newFolder");
                QMessageBox::information(this,tr("Completed"),tr("completed"));
                procA.closeWriteChannel();
                QByteArray outputA;
                if(procA.waitForReadyRead()){
                    outputA += procA.readAll();
                }
                qDebug() << outputA;//your code here
                procA.write("exit");
                procA.waitForFinished();
                
                QT_QT_QTQ Offline
                QT_QT_QTQ Offline
                QT_QT_QT
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • jsulmJ jsulm

                  More like:

                  QProcess procA();
                  /procA.setWorkingDirectory("C:\\Users\\USER\\Desktop\\FileA\\FileB");
                  procA.start("cmd",QStringList());
                  procA.start("cmd");
                  if(!procA.waitForStarted()){
                      return ;
                  }
                  procA.write("mkdir newFolder");
                  QMessageBox::information(this,tr("Completed"),tr("completed"));
                  procA.closeWriteChannel();
                  QByteArray outputA;
                  if(procA.waitForReadyRead()){
                      outputA += procA.readAll();
                  }
                  qDebug() << outputA;//your code here
                  procA.write("exit");
                  procA.waitForFinished();
                  
                  QT_QT_QTQ Offline
                  QT_QT_QTQ Offline
                  QT_QT_QT
                  wrote on last edited by QT_QT_QT
                  #8

                  @jsulm

                  Hi, thank you for the example that you had provided. I did not get any error messages when i compile them. However, the QProcess doesnt execute properly, which means I did not see any newFolder in the directory. Not only that, every time i pressed the "exit"button on the ui form, whole GUI will stay in freeze mode.

                  So, i assumed maybe that directory is not correct, the computer can not recognize the directory. Hence on, I modified my code into like this :

                  procA.setWorkingDirectory("C://Users//USER//Desktop//FileA//FileB");
                  procA.setWorkingDirectory("C:/Users/USER/Desktop/FileA/FileB/");
                  procA.setWorkingDirectory("C:\Users\USER\Desktop\FileA\FileB");
                  procA.setWorkingDirectory("C:\Users\USER\Desktop\FileA\File\B");

                  Despite the modfication that i done for my code, the process still doesn't execute properly, i do not see any newFolder in that directory . What should I do to elimate / avoid this error keep happening . Thanks

                  ***Ps: I m using window 8.1 64 bit

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

                    First: why do you have two start() calls?

                    procA.start("cmd",QStringList());
                    procA.start("cmd");
                    

                    Second: you have to append new line to each command you're sending to cmd (as you would do in cmd window to enter a command):

                    procA.write("mkdir newFolder\n");
                    

                    For paths you can use slash:

                    procA.setWorkingDirectory("C:/Users/USER/Desktop/FileA/FileB");
                    

                    With these changes it is working for me.

                    The UI is freezing because you are waiting for QProcess in your UI thread.

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

                    1 Reply Last reply
                    2
                    • QT_QT_QTQ Offline
                      QT_QT_QTQ Offline
                      QT_QT_QT
                      wrote on last edited by
                      #10

                      Hi,

                      speaking of this procA.start("cmd",QStringList());
                      //procA.start("cmd");

                      i was just trying which line will work.When i copy and paste the code to here, I was totally forget to remove one of the line. My apologies .

                      Right now, the process is executing properly . Thanks to you!

                      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