Results 1 to 6 of 6

Thread: QProcess to start running an external executable

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess to start running an external executable

    Hi

    Could You kindly guide me in using QProcess in Qt4 to run an external application.

    Now i have used the below 2 lines in the .cpp file but it does not start the process .

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);
    QProcess proc;
    QProcess proc;
    proc.start("./Path _to_executable "); // start program .exe

    }

    Please advice as to how to run an external executable from qt other than using system command

  2. #2
    Join Date
    Feb 2010
    Posts
    16
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: QProcess to start running an external executable

    Try using it like this:
    Qt Code:
    1. QProcess* process = new QProcess();
    2. QString program = "c:\\windows\\system32\\calc.exe";
    3. process->start(program);
    To copy to clipboard, switch view to plain text mode 
    make sure you use \\ (double \) for a Folder inside the string...

  3. #3
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess to start running an external executable


    Yes i did try but though it compiles , it does not run the executable.
    Is there any other option other than QProcess?

    My aim is to run an external executable from Qt preferably on the Qt's widget itself. Do suggest.
    Waiting for ur reply.

  4. #4
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QProcess to start running an external executable

    So you want to embedd another executable inside the widgets of your own QWidgets? There are various solutions available, depending on the technologies used to create the application to be embedded. Have a look at the QtSolutions: http://qt.nokia.com/products/appdev/...ucts/catalog/4 (See migration).

    There is no general cross plattform solution for embedding arbitrary applications.
    It's nice to be important but it's more important to be nice.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QProcess to start running an external executable

    As presented, the QProcess instance goes out of scope at the end of the constructor and the QProcess destructor then terminates the process. If you want the process to persist for the life of the widget then you need to allocate the QProcess on the heap, or make it a member variable of the class.

  6. #6
    Join Date
    Dec 2009
    Location
    New Hampshire, USA
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess to start running an external executable

    I am having a very similar problem. I created a very small project, the point of which was to test how to use QProcess to launch applications. The same code that works to lauch Microsoft's Calculator ("calc.exe") won't launch my application. My application launches just fine from a DOS prompt or from Windows Explorer (doubleclick). Here is my code:

    Qt Code:
    1. QString programName("c:/pcs");
    2. QStringList arguments;
    3.  
    4. process_ptr = new QProcess(this); //process_ptr is declared in my header file QProcess *process_ptr;
    5. connect(process_ptr,SIGNAL(started()),this,SLOT(OnStarted()));
    6. process_ptr->start(programName, arguments);
    To copy to clipboard, switch view to plain text mode 

    When I run this, my OnStarted() slot is called, so the QProcess object is emitting started(). But the first thing the application I am trying to launch does in main() is to create a file, which never happens when I try to launch it with the above code.

    I'm sure there is something about my c:/pcs.exe app that is making it not work, but I have no idea what.

Similar Threads

  1. How to start external application from QT?
    By TomASS in forum Newbie
    Replies: 10
    Last Post: 7th November 2009, 17:57
  2. How to reload QProcess executable?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 20:13
  3. Qt3 qprocess, executable exited?
    By triperzonak in forum Newbie
    Replies: 2
    Last Post: 22nd September 2008, 11:21
  4. Replies: 10
    Last Post: 17th December 2007, 11:29
  5. Error running executable
    By Salazaar in forum Newbie
    Replies: 8
    Last Post: 21st May 2007, 06:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.