PDA

View Full Version : How to start a process(application) on windows? (solved)



sutee84
13th March 2010, 12:47
Hi!

I wrote a small code on linux, what start a firefox browser, it works on ubuntu, but I tried it on windows, and it doesn't work.

The code:
QProcess process;
process.start("firefox"); //I also tried process.start("C:/Program Files/Mozilla Firefox/firefox.exe");

Can somebody help me?

Regards,
Sutee84

squidge
13th March 2010, 12:53
Are you sure the path is correct? Try typing it into the Start->Run box first.

Secondly, a string like C:\ProgramFiles\Mozilla-firefox\firefox.exe wil never work, as \ is an escape character. Try C:\\ProgramFiles\\Mozilla-firefox\\firefox.exe instead.

Or, if opening a web page is your goal, just pass the web page url to the os, and the default browser will be opened.

Lykurg
13th March 2010, 12:57
Does "C:/Program Files/Mozilla Firefox/firefox.exe" really exist on your computer? You can try backslashes, but I don't think that's an issue here. Try use QProcess::execute().

EDIT: Too late...
EDIT: For the last paragraph of fatjuicymole see QDesktopServices.

sutee84
13th March 2010, 13:13
Yes the path is good, because I get it with QFileDialog, and store it in a QString, but I think, the problem is with the QString, but I don't know, how can I remove the spaces from the QString.

Lykurg
13th March 2010, 13:35
What spaces? They are part of the path. YOu can't remove them. But use QString::trimmed() and QDir::toNativeSeparators(). This might help.

sutee84
13th March 2010, 14:03
I solved the problem:
ffpath.replace("\/","\\");
process.start("\""+ffpath+"\"");

And it works!
Thx!