Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Running external Python 3 script

    General and Desktop
    4
    7
    228
    Loading More Posts
    • 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
      Saltywaffles last edited by

      I want to run an external .py script that I made. I have tested the script in VS and it runs fine. When I try to implement it in QT, it will not open. Here is what I have in my .cpp file:

      QString path = "C:/../python.exe";
      QString  command("python");
      QStringList params = QStringList() << "C:/../test.py";
      
      QProcess *process = new QProcess();
      process->startDetached(command, params, path);
      process->waitForFinished();
      process->close();
      

      I do not get any errors when pressing the button, in fact, I get nothing from the output. Any ideas?

      JonB aha_1980 2 Replies Last reply Reply Quote 0
      • JonB
        JonB @Saltywaffles last edited by

        @saltywaffles
        What do you mean by "it will not open."? "I get nothing from the output." what output? Why are you using QProcess::startDetached() to run your script? How do you know it does not run?

        1 Reply Last reply Reply Quote 2
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          If you want know know exactly what is going on, you should not call startDetached.

          Start your QProcess normally and check the it starts correctly and for errors.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply Reply Quote 2
          • S
            Saltywaffles @SGaist last edited by

            @sgaist

            How would that look? I am a little lost figuring out the Qprocess

            JonB 1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              You have an example in the Synchronous Process API part of QProcess's documentation.

              You have the error method.

              You should also check the communication channels. Read the content of the standard output and standard error to see what is happening.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 3
              • JonB
                JonB @Saltywaffles last edited by JonB

                @saltywaffles
                You will need to look at the links @SGaist has given you and implement. But first things first: have you replaced startDetached() by start(), does that behave differently for you? Or you might find the static https://doc.qt.io/qt-5/qprocess.html#execute a simpler place to start out from: its return code at least tells you what happened when invoking the process, before you proceed to pick up the output. The problem is you still have not explained what you mean by "I get nothing from the output." Does your script send output to stdout which you see when you run it elsewhere (e.g. a terminal) and you want to capture that out in your Qt program?

                1 Reply Last reply Reply Quote 0
                • aha_1980
                  aha_1980 Lifetime Qt Champion @Saltywaffles last edited by

                  @saltywaffles which Qt version are you using?

                  Qt has to stay free or it will die.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post