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. [SOLVED] Execute cmd using qt on Windows.
QtWS25 Last Chance

[SOLVED] Execute cmd using qt on Windows.

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

    I have a GUI with a button to search a file and button OK to open a file (e.g .txt) using cmd.
    In my function_on_buttonBox_OK_ I wrote the follow code:
    @
    QProcess proc;
    QString command = "cmd.exe";
    QStringList arguments =
    QStringList() << item2;
    proc.start(command, arguments);@

    ps: item2 is a string that contains the directory of my text file that I previously adiquiri.

    But has an error: QProcess: Destroyed while process ("cmd.exe") is still running.

    Someone help me ?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

      Most probably you are deleting proc before the end of the process. Based on the code snippet that you have published I see that you assign the variable at the stack which means that it will be deleted automatically when it goes out of scope.

      http://anavi.org/

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Neutrox
        wrote on last edited by
        #3

        How can I fiz this ?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          You can use "waitForStarted":http://qt-project.org/doc/qt-5/qprocess.html#waitForStarted to make sure that cmd.exe is started and then "waitForFinished":http://qt-project.org/doc/qt-5/qprocess.html#waitForFinished to make sure that cmd.exe is finished.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Neutrox
            wrote on last edited by
            #5

            Works like this:
            @ QString paths = item2;
            QProcess proc;
            QString command = "cmd.exe";
            QStringList arguments =
            QStringList() << "/c" << paths ;

            proc.start(command, arguments);
            if(proc.waitForStarted()){
                qDebug() << "Starting";
            }
            proc.waitForFinished(-1);
                qDebug() << "finish";@
            

            But I have a question:
            Why does my GUI freezes when I open a file in directory C: (system) and does not freezes when I open in directory E: (I divided my HD into two parts) ?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              I guess that you call cmd.exe in the main thread, so it should freeze in both cases, maybe it reads faster from E:

              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