Results 1 to 11 of 11

Thread: How to start external application from QT?

  1. #1
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QString program = "iexplore";
    4. QStringList arguments;
    5.  
    6. QProcess *myProcess = new QProcess(this);
    7. myProcess->start(program, arguments);
    8. qDebug()<<myProcess->errorString();
    9. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Apr 2009
    Posts
    46
    Thanks
    4
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to start external application from QT?

    Wrong path I believe.

    An example of working one would be:
    Qt Code:
    1. QString program = "C:\\WINDOWS\\system32\\winmine.exe";
    2. QStringList arguments;
    3. QProcess *myProcess = new QProcess(qApp);
    4. myProcess->start(program, arguments);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to start external application from QT?

    Quote Originally Posted by RSX View Post
    Wrong path I believe.

    An example of working one would be:
    Qt Code:
    1. QString program = "C:\\WINDOWS\\system32\\winmine.exe";
    2. QStringList arguments;
    3. QProcess *myProcess = new QProcess(qApp);
    4. myProcess->start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    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"?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  5. #5
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to start external application from QT?

    Quote Originally Posted by fatjuicymole View Post
    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:
    Qt Code:
    1. C:\Program Files\Microsoft Office\Office12\
    To copy to clipboard, switch view to plain text mode 
    Whith is a outlook.exe isn't in PATH in system enviroment, so:
    Qt Code:
    1. QStringList env = QProcess::systemEnvironment();
    2. QString program = "outlook.exe";
    3. QStringList arguments;
    4. QProcess *myProcess = new QProcess(qApp);
    5. myProcess->setEnvironment(env);
    6. myProcess->start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    isn't work either :/

    about the fact that easier use url handler, in mailto:
    Qt Code:
    1. QDesktopServices::openUrl(QUrl::QUrl("mailto:tomek@tomek.pl?subject=myreport&body=seeattachment&attachment=C:\\tomek.txt'"));
    To copy to clipboard, switch view to plain text mode 
    unfortunately the attachment isn't work :/

  6. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to start external application from QT?

    Also possible is
    Qt Code:
    1. QProcess::startDetached("c:/path/to/program.exe");
    To copy to clipboard, switch view to plain text mode 
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  7. #7
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to start external application from QT?

    Quote Originally Posted by franz View Post
    Also possible is
    Qt Code:
    1. QProcess::startDetached("c:/path/to/program.exe");
    To copy to clipboard, switch view to plain text mode 
    As I've said

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

  8. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  9. The following user says thank you to squidge for this useful post:

    TomASS (2nd November 2009)

  10. #9
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to start external application from QT?

    Quote Originally Posted by fatjuicymole View Post
    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:
    Qt Code:
    1. "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"
    To copy to clipboard, switch view to plain text mode 


    when I'm doing:
    Qt Code:
    1. QString program = "\"C:\\Program Files\\Microsoft Office\\Office12\\OUTLOOK.EXE\" /a \"c:\\tomek.txt\"";
    2. QProcess *myProcess = new QProcess(qApp);
    3. myProcess->start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    the outlook shows me:

    Qt Code:
    1. command line argument is invalid
    To copy to clipboard, switch view to plain text mode 
    but when I paste a
    Qt Code:
    1. "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /a "c:\tomek.txt"
    To copy to clipboard, switch view to plain text mode 
    in start->run It works very fine :/

  11. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  12. The following user says thank you to squidge for this useful post:

    TomASS (7th November 2009)

  13. #11
    Join Date
    Apr 2009
    Posts
    75
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to start external application from QT?

    Yes! You've a right! Thanks

Similar Threads

  1. Replies: 3
    Last Post: 20th November 2014, 07:10
  2. Q3ScrollView resists to scroll down to the garbage bin
    By sivrisinek in forum Qt Programming
    Replies: 0
    Last Post: 5th February 2009, 17:50
  3. shared vs static
    By alisami in forum Installation and Deployment
    Replies: 3
    Last Post: 4th October 2008, 13:04
  4. Replies: 16
    Last Post: 23rd May 2008, 10:12
  5. Start Qt application as Windows Service
    By ^NyAw^ in forum Qt Programming
    Replies: 12
    Last Post: 10th May 2008, 17:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.