Qt QProcess Tutorial

When I use Qt, I try to used or start external program from Qt. After searching in qassistant, I get a class QProcess to used or start external program from Qt. So, I try to create Qt QProcess tutorial in my post. This my Qt QProcess tutorial is basic tutorial to use QProcess in Qt. I try to create a Qt QProcess tutorial to call another command or external program from Qt and display success or error message if that program have.

Before we can use QProcess class, we must include <QProcess> in our header program. I create this Qt QProcess tutorial to running under linux. I use bash script to process string from user typed. If program called have success or error message, this Qt program will print that string with function readAllStandardOutput (if program success) or readAllStandardError (if program error).

This is a my simple script function in Qt QProcess tutorial to use QProcess and print output if program success or fail.

This Qt QProcess tutorial will print text with color black (if success) and red if fail/error. This is output from this code :

If you want to running this program under windows, you must modified this code proc->start(). Because, I communicate user typed command with bash script, and windows dont have bash. This is a simple Qt QProcess tutorial. So, you can know how to use QProcess in your application. You can read the complete QProcess class in Qt Documentation.  You can download all this code in this location.

5 thoughts on “Qt QProcess Tutorial

  1. i test your programm(qt terminal ) , it seem work fine but the ” cd ” command didnot, how can i correct this ?
    and thank you for your tutorial

  2. Hi,
    I am not able to download the source code for this as it is opening some fly ad website while i click on “You can download all this code in this location.” so reply how can I download the same.

  3. Hi Toto,

    When I try to download your Qt QProcess Tutorial source code,
    It jumps to the website Open Download manager.

    Can you send me source code ?

    I am a Qt beginner.
    Thanks a lot,

  4. thank you for this tutorial

    how to make Qprocess run a command line as Root in linux (shutdown for exemple), let supose that you have the user name and the password in your variables

    can you help me with that

Leave a Reply to adel Cancel reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.