Qt - QProcess is not working

12,101

Solution 1

Try:

QProcess * process=new QProcess(this);
QString temp="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\"";
process->startDetached(temp);

You need to use escaped quotes since the path has a space in it, or possibly escape all the spaces (you missed Program\ Files in the code you posted).

Solution 2

How about that?

QDir dir("C:\\");
QProcess::execute("explorer.exe", QStringList() << dir.toNativeSeparators(dir.path()));
Share:
12,101
prabhakaran
Author by

prabhakaran

A newbie to qt,openGL,NetworkProgramming Know python,perl,shell scripting. A well versed(medium level) C++,linux,perl,c# programmer Crawling around javascript,xul and new technologies. I am a Linux lover got tricked into windows.

Updated on June 28, 2022

Comments

  • prabhakaran
    prabhakaran almost 2 years

    I try to launch internet explorer, So I use the below code

    QProcess * process=new QProcess(this);
    QString temp="C:\\Program Files\\Internet\ Explorer\\iexplore.exe";
    process->startDetached(temp.toStdString().c_str());
    

    But it doesn't work.

  • Frank Osterfeld
    Frank Osterfeld over 13 years
    Even easier than escaping: use startDetached(temp, QStringList()). That one will do the escaping itself. I would always prefer the variant of QProcess::start/startDetached etc. that takes the args as QStringList, to avoid quoting issues.
  • Adam W
    Adam W over 13 years
    @Frank: almost, but the problem is that the program name has spaces not the arguments, so you still need to quote or escape the path.
  • Frank Osterfeld
    Frank Osterfeld over 13 years
    No, you don't. If you use the QStringList() overload, there is no quoting necessary. QProcess::startDetached(QLatin1String("/path/to/Foo Bar"), QStringList()) works, while QProcess::startDetached(QLatin1String("/path/to/Foo Bar")) fails. There is no reason in the former case to interpret "Bar" as arguments, as the arguments are passed separately. Qt does the Right Thing and builds the correct commandline internally.
  • Adam W
    Adam W over 13 years
    @Frank: Hm, never actually had to use this before, good to know.