PDA

View Full Version : QProcess to start running an external executable



Raggio
11th February 2010, 13:45
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

HeX0R
11th February 2010, 14:16
Try using it like this:


QProcess* process = new QProcess();
QString program = "c:\\windows\\system32\\calc.exe";
process->start(program);

make sure you use \\ (double \) for a Folder inside the string...

Raggio
12th February 2010, 07:15
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.

axeljaeger
12th February 2010, 09:48
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/add-on-products/catalog/4 (See migration).

There is no general cross plattform solution for embedding arbitrary applications.

ChrisW67
12th February 2010, 23:20
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.

AwareWolf
17th March 2010, 18:30
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:



QString programName("c:/pcs");
QStringList arguments;

process_ptr = new QProcess(this); //process_ptr is declared in my header file QProcess *process_ptr;
connect(process_ptr,SIGNAL(started()),this,SLOT(On Started()));
process_ptr->start(programName, arguments);


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.