How to start external application from QT?
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:
Code:
void MainWindow::on_pushButton_clicked()
{
myProcess->start(program, arguments);
qDebug()<<myProcess->errorString();
}
qDebug shows me
Quote:
"Process failed to start"
What i'm doing wrong?
Re: How to start external application from QT?
Wrong path I believe.
An example of working one would be:
Code:
QString program
= "C:\\WINDOWS\\system32\\winmine.exe";
myProcess->start(program, arguments);
Re: How to start external application from QT?
Quote:
Originally Posted by
RSX
Wrong path I believe.
An example of working one would be:
Code:
QString program
= "C:\\WINDOWS\\system32\\winmine.exe";
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"?
Re: How to start external application from QT?
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.
Re: How to start external application from QT?
Quote:
Originally Posted by
fatjuicymole
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:
Code:
C:\Program Files\Microsoft Office\Office12\
Whith is a outlook.exe isn't in PATH in system enviroment, so:
Code:
myProcess->setEnvironment(env);
myProcess->start(program, arguments);
isn't work either :/
about the fact that easier use url handler, in mailto:
Code:
QDesktopServices::openUrl(QUrl::QUrl("mailto:tomek@tomek.pl?subject=myreport&body=seeattachment&attachment=C:\\tomek.txt'"));
unfortunately the attachment isn't work :/
Re: How to start external application from QT?
Also possible is
Code:
QProcess::startDetached("c:/path/to/program.exe");
Re: How to start external application from QT?
Quote:
Originally Posted by
franz
Also possible is
Code:
QProcess::startDetached("c:/path/to/program.exe");
As I've said
It isn't possible to known all users' path to outlook....
Re: How to start external application from QT?
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.
Re: How to start external application from QT?
Quote:
Originally Posted by
fatjuicymole
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:
Code:
"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"
when I'm doing:
Code:
QString program
= "\"C:\\Program Files\\Microsoft Office\\Office12\\OUTLOOK.EXE\" /a \"c:\\tomek.txt\"";
myProcess->start(program, arguments);
the outlook shows me:
Code:
command line argument is invalid
but when I paste a
Code:
"C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"
in start->run It works very fine :/
Re: How to start external application from QT?
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.
Re: How to start external application from QT?
Yes! You've a right! Thanks