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] How to use QProcess?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to use QProcess?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.9k Views 1 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.
  • S Offline
    S Offline
    skammers
    wrote on last edited by
    #1

    I am not so used to Qt and QML. What I want to do is start another .exe program from my program.
    So I have a .lng file which I need to send through another .exe file for converting.

    Can anyone show me how to do this?
    Seen that I could use QProcess, but reading the documentation, I really didnt feel any smarter.
    I've seen a couple of other examples as well, without really understanding how to do it, and how QProcess works.

    Thanks for any reply.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Going through the "QProcess":http://qt-project.org/doc/qt-5/QProcess.html doc you can see how to start a QProcess and how to pass arguments to it.
      In your case your .exe file is a program and the .lng file which you want to send to it would be the arguments to it.
      So starting QProcess would be similar to following in your case,
      @
      QString program = "D:/Sample.exe"; //Complete path to your .exe file
      QStringList arguments;
      arguments << "D:/Sample.lng"; //Complete path to your .lng file

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

      Please go through the QProcess doc for a complete understanding of how it works.

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        To expand on p3c0's answer... If your exe exits when it's done with the conversion you can wait for it to exit to know it's done before you proceed with whatever you needed the converted data for.

        To do that, just add a slot for the finished signal.

        @
        void myClass::someFunc()
        {
        QProcess myProcess = new QProcess(this);
        connect(myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processDone(int, QProcess::ExitStatus)));
        myProcess->start("/path/to/exe", QStringList() << "your_file_to_process.ing");
        }

        void MyClass::processDone(int exitCode, QProcess::ExitStatus es)
        {
        if (exitCode || es != QProcess::NormalExit)
        {
        // usually a problem if it's not 0, handle it, or not
        return;
        }

        // all good, so handle your converted data here...
        }
        @

        I normally wouldn't pass this to QProcess but since it was in that function and the pointer would go out of scope without you being able to clean it up, I added that for memory clean up. Normally in that situation I would have a class member variable like mProcess so I could keep track and clean up the pointer later on. Plus it allows you to continue to access the QProcess until you're done with it.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        0
        • S Offline
          S Offline
          skammers
          wrote on last edited by
          #4

          Thank you!

          This works perfectly.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            No problem! :)

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            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