PDA

View Full Version : How to start external application from QT?



TomASS
2nd November 2009, 15:24
Hi,

I'ld like to start external application from QT - for example "iexmplore", "outlook.exe" etc.... how can I do it? If i've wrote:

void MainWindow::on_pushButton_clicked()
{
QString program = "iexplore";
QStringList arguments;

QProcess *myProcess = new QProcess(this);
myProcess->start(program, arguments);
qDebug()<<myProcess->errorString();
}

qDebug shows me

"Process failed to start"
What i'm doing wrong?

RSX
2nd November 2009, 16:47
Wrong path I believe.

An example of working one would be:

QString program = "C:\\WINDOWS\\system32\\winmine.exe";
QStringList arguments;
QProcess *myProcess = new QProcess(qApp);
myProcess->start(program, arguments);

TomASS
2nd November 2009, 18:33
Wrong path I believe.

An example of working one would be:

QString program = "C:\\WINDOWS\\system32\\winmine.exe";
QStringList arguments;
QProcess *myProcess = new QProcess(qApp);
myProcess->start(program, arguments);

Yes, that's correct, but I don't known where is (for example) "outlook.exe" in any my program's users - I'm just writting "outlook.exe" in start->run and It's working - why in this case can't I write only simple "outlook.exe"?

squidge
2nd November 2009, 19:29
Start->Run iterates through all the system paths if the executable isn't found in the current directory. You could do this yourself (the path is stored in an environment variable), but depending on what you actually want to do, the url handler may be easier.

TomASS
2nd November 2009, 20:07
Start->Run iterates through all the system paths if the executable isn't found in the current directory. You could do this yourself (the path is stored in an environment variable), but depending on what you actually want to do, the url handler may be easier.

The path:

C:\Program Files\Microsoft Office\Office12\
Whith is a outlook.exe isn't in PATH in system enviroment, so:

QStringList env = QProcess::systemEnvironment();
QString program = "outlook.exe";
QStringList arguments;
QProcess *myProcess = new QProcess(qApp);
myProcess->setEnvironment(env);
myProcess->start(program, arguments);
isn't work either :/

about the fact that easier use url handler, in mailto:

QDesktopServices::openUrl(QUrl::QUrl("mailto:tomek@tomek.pl?subject=myreport&body=seeattachment&attachment=C:\\tomek.txt'"));
unfortunately the attachment isn't work :/

franz
2nd November 2009, 20:13
Also possible is

QProcess::startDetached("c:/path/to/program.exe");

TomASS
2nd November 2009, 20:22
Also possible is

QProcess::startDetached("c:/path/to/program.exe");
As I've said

It isn't possible to known all users' path to outlook....

squidge
2nd November 2009, 21:59
Well, you could use OLE/VBA as Outlook will register a server so it'll load when you access it and then you can have full control over it.

There's also the application registry. For example, if you were to type "outlook", you would find this:

[HKEY_CLASSES_ROOT\applications\OUTLOOK.EXE\shell\o pen\command]
@="\"C:\\Program Files\\Microsoft Office\\Office10\\OUTLOOK.EXE\" \"%1\""

In other words, exactly where "outlook.exe" is stored, and how to run it. There are many other applications here also, which can also be started just by typing there name into the start/run box.

TomASS
2nd November 2009, 22:55
Well, you could use OLE/VBA as Outlook will register a server so it'll load when you access it and then you can have full control over it.

There's also the application registry. For example, if you were to type "outlook", you would find this:

[HKEY_CLASSES_ROOT\applications\OUTLOOK.EXE\shell\o pen\command]
@="\"C:\\Program Files\\Microsoft Office\\Office10\\OUTLOOK.EXE\" \"%1\""

In other words, exactly where "outlook.exe" is stored, and how to run it. There are many other applications here also, which can also be started just by typing there name into the start/run box.

Ok, thanks, I've a path from registry, although not the
[HKEY_CLASSES_ROOT\applications\OUTLOOK.EXE\shell\o pen\command] (i've not a shell\open\command) only for HKEY_CLASSES_ROOT\\Outlook.File.msg\\shell\\Open\\ command,

i've a string:

"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"


when I'm doing:

QString program = "\"C:\\Program Files\\Microsoft Office\\Office12\\OUTLOOK.EXE\" /a \"c:\\tomek.txt\"";
QProcess *myProcess = new QProcess(qApp);
myProcess->start(program, arguments);
the outlook shows me:


command line argument is invalid
but when I paste a

"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"
in start->run It works very fine :/

squidge
2nd November 2009, 23:26
Why the extra quotes?

'program' should just be that, "C:\\Program Files\\Microsoft Office\\Office12\\OUTLOOK.EXE". No escaped quotes.

If you want arguments such as "/A", then put them into the 'arguments' QStringList.

TomASS
7th November 2009, 17:57
Yes! You've a right! Thanks