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. Starting an external exe from Qt
Forum Updated to NodeBB v4.3 + New Features

Starting an external exe from Qt

Scheduled Pinned Locked Moved General and Desktop
11 Posts 7 Posters 22.1k Views 2 Watching
  • 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.
  • O Offline
    O Offline
    ommz
    wrote on last edited by
    #1

    Hi. I tried using the code from the example of the analog clock in the Qt manual after modifying it a little but it still has a logical error. The plan is that when I click a button, it is supposed to open an exe file. Would someone please show me a snippet of the correct implementation of the code.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      external processes are started by QProcess.
      What did you do? can you show us your code so we can ahve a look at it?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • V Offline
        V Offline
        veeraps
        wrote on last edited by
        #3

        Refer 'Running a Process' segment under the documentation of "QProcess":http://qt-project.org/doc/qt-4.8/qprocess.html

        Have you tried it already? Do you face any issue or error?

        1 Reply Last reply
        0
        • O Offline
          O Offline
          ommz
          wrote on last edited by
          #4

          Thats where I got the snippet but after editing it to suit my app, it does not work. Here's the snippet:

          @
          QObject *parent;
          ...
          QString program = "C:/programs/bin/snort.exe";
          QStringList arguments;
          arguments << "-d";

           QProcess *myProcess = new QProcess(parent);
           myProcess->start(program, arguments);
          

          @

          [Edit: Added @ tags; mlong]

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Moved to the General forum, as this is nothing for the C++ gurus :)

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • V Offline
              V Offline
              veeraps
              wrote on last edited by
              #6

              Would you tell us what is the error that you are getting or better send in the full code snippet.

              Also try the prefix and suffix your code by @ symbol, so that you get the code in good format
              @QObject *parent;
              …
              QString program = “C:/programs/bin/snort.exe”;
              QStringList arguments; arguments << “-d”;

              QProcess *myProcess = new QProcess(parent);
              myProcess->start(program, arguments);@

              What is parent? It is not allocated with any value and that is being used as the parent for QProcess(). Remember you can pass '0' to QProcess as well or simply don't pass any value, which will default parent pointer to null.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ommz
                wrote on last edited by
                #7

                A simple way in Windows would be:
                (in the slot for the button)
                @
                void MainWindow::on_pushButton_clicked()
                {
                system ("start C:\snort\bin\snort.exe");

                }
                @

                [edit] Added code tags, koahnig

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  [quote author="ommz" date="1339741582"]A simple way in Windows would be:
                  (in the slot for the button)
                  @
                  void MainWindow::on_pushButton_clicked()
                  {
                  system ("start C:\snort\bin\snort.exe");

                  }
                  @
                  [/quote]

                  Certainly this is a way to do under windows, but it have another implementation for other OS.

                  QProcess is wrapping the different methods and adds additional comfort. You can redirect" the input and output":http://qt-project.org/doc/qt-4.8/qprocess.html#communicating-via-channels through Qt.

                  The equivalent to your simple program above would be using "the static execute method. ":http://qt-project.org/doc/qt-4.8/qprocess.html#execute-2

                  @
                  void MainWindow::on_pushButton_clicked()
                  {
                  QProcess::execute ("start C:\snort\bin\snort.exe");
                  }
                  @

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    ktwalker
                    wrote on last edited by
                    #9
                    This post is deleted!
                    A 1 Reply Last reply
                    0
                    • K ktwalker

                      This post is deleted!

                      A Offline
                      A Offline
                      arsinte_andrei
                      wrote on last edited by
                      #10

                      @ktwalker said in Starting an external exe from Qt:

                      QProcess as used above in its two different methods start and execute does not work for me with Qt5 on Windows 10. Not sure why. system() works though.

                      if you need some help why do you not start another post here on forum rather then take a topic that was 7 years ago... a long way back - since then Qt changed a lot...

                      Start a new topic on this forum, describe your problem as best as you can, provide some more info about your PC and software that you are running (windows GNU/Linux macOs), Qt version.. what are you trying to do and how...
                      Then we will be able to help..

                      K 1 Reply Last reply
                      2
                      • A arsinte_andrei

                        @ktwalker said in Starting an external exe from Qt:

                        QProcess as used above in its two different methods start and execute does not work for me with Qt5 on Windows 10. Not sure why. system() works though.

                        if you need some help why do you not start another post here on forum rather then take a topic that was 7 years ago... a long way back - since then Qt changed a lot...

                        Start a new topic on this forum, describe your problem as best as you can, provide some more info about your PC and software that you are running (windows GNU/Linux macOs), Qt version.. what are you trying to do and how...
                        Then we will be able to help..

                        K Offline
                        K Offline
                        ktwalker
                        wrote on last edited by
                        #11

                        @arsinte_andrei My apologies. I just wanted to let people who see this know there is an issue with it without going into the depth. I did more investigating and determined the problem is related to a drive path issue with my OneDrive. I have posted a new post to the Qt C++ Guru's group. I've also deleted my incorrect post above.

                        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