Results 1 to 7 of 7

Thread: QDesktopServices or QProcess for launching external applications

  1. #1
    Join Date
    Jul 2009
    Location
    Oulu, Finland
    Posts
    23
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QDesktopServices or QProcess for launching external applications

    Hey,

    I need to launch some external applications from my own program. So here's the simple question, which is preferred way to launch those applications QDesktopServices or QProcess?

    I have done a small test with these and I would like to use QDesktopServices for this, but there seems to be some problem when trying to launching application executables.

    Here's some code to clear things up...

    Opening default web browser with some web page. This does the job as expected, good
    Qt Code:
    1. QDesktopService::openUrl(QUrl("http://www.qtcentre.org"));
    To copy to clipboard, switch view to plain text mode 
    This is obviously because these kind of "resources" are marked to be opened with the web browser

    Then there's also ability to open some files, for example self-executable JAR packages, with the same method
    Qt Code:
    1. QDesktopService::openUrl(QUrl("file:////path/to/the/package.jar"));
    To copy to clipboard, switch view to plain text mode 
    This also goes as expected since Java Runtime is selected to be associated with this file type

    Now, here comes the odd part. I would expect next code sample...
    Qt Code:
    1. QDesktopService::openUrl(QUrl("file:////path/to/the/executable"));
    To copy to clipboard, switch view to plain text mode 
    ... to start the application but it won't, instead it says in the console: "Error showing url: No application is registered as handling this file". This happens only in Linux, with Windows the executable is launched as expected... (of course with Windows the path in QUrl is different)
    I understand that there's no application associated with these kind of files (executables), but shouldn't the system understand that the executable is just meant to be launched

    Also the code...
    Qt Code:
    1. QString program = "/path/to/the/executable";
    2. QStringList arguments;
    3.  
    4. QProcess *process = new QProcess(this);
    5. process->start(program, arguments);
    To copy to clipboard, switch view to plain text mode 
    is able to launch the application just fine.

    So, do I have to use these both tehcniques to achieve what I want? Or is there a way to get the QDesktopServices to launch executables as expected, also in Linux? Maybe something to tweak from the Linux's settings? (I'm using Ubuntu, btw)

    -Tepi

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDesktopServices or QProcess for launching external applications

    openUrl() is for opening a data file using a default handler for this file in the file system. So passing it an executable would try to find a program to open this executable with (like a hex editor or something). This is not what you want. Use QProcess.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Tepi (25th January 2010)

  4. #3
    Join Date
    Jul 2009
    Location
    Oulu, Finland
    Posts
    23
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices or QProcess for launching external applications

    Thanks for your reply, wysota.

    I'll use QProcess then. Although it would seem quite logical to be able to launch also executables with QDesktopServices, but that's only my opinion I understand that QDesktopServices is designed for the purpose of opening differend kind of file types with their default handlers.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDesktopServices or QProcess for launching external applications

    Quote Originally Posted by Tepi View Post
    I'll use QProcess then. Although it would seem quite logical to be able to launch also executables with QDesktopServices, but that's only my opinion
    Why? This class is for opening a datafile with a program. In my system I can have a default file handler for .exe files to be set to open them in a hex editor or something. What should QDesktopServices do if I passed it such an exe file? Open it in the hex editor or run the executable?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Jul 2009
    Location
    Oulu, Finland
    Posts
    23
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices or QProcess for launching external applications

    My opinion is that if you have set some special file handler for the .exe files (which I think is quite rare occasion) then it should be opened with that handler (for example that hex editor), otherwise it should just be executed (as there's no file handlers assigned for the type). And again this is just my humble opinion and the first impression which I had when I tried the QDesktopServices

    Btw, on Windows it launches the .exe file automatically if you haven't changed the handler for the .exe files. So this is why i was assuming the same functionality for the Linux systems... I don't know if this is a distribution dependent issue, but at least with Ubuntu it won't launch it.

    And thanks again for the comments Wysota.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDesktopServices or QProcess for launching external applications

    Quote Originally Posted by Tepi View Post
    My opinion is that if you have set some special file handler for the .exe files (which I think is quite rare occasion) then it should be opened with that handler (for example that hex editor), otherwise it should just be executed (as there's no file handlers assigned for the type). And again this is just my humble opinion and the first impression which I had when I tried the QDesktopServices
    And if we were talking about an image type? Should the image be executed too if there was no handler assigned to it? What purpose would it serve?

    Btw, on Windows it launches the .exe file automatically if you haven't changed the handler for the .exe files.
    "It" meaning what? QDesktopServices? Maybe there's a handler installed for executable files on Windows. There is no such handler on Unix systems, it wouldn't make much sense. It is the executable bit that marks if the file can be executed or not and not the file type.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jul 2009
    Location
    Oulu, Finland
    Posts
    23
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDesktopServices or QProcess for launching external applications

    And if we were talking about an image type? Should the image be executed too if there was no handler assigned to it? What purpose would it serve?
    Nope, of course not. That's not the point. In the case some image type doesn't have handler assigned, system would ask user with what program the file should be opened, as it is doing now by default. Why would the image file type have "execute" permissions? I see no point on that...

    So when we have some executable file with "execute" permissions which has no hadler assigned to it, wouldn't it seem logical just to launch it?

    "It" meaning what? QDesktopServices?
    Yep, "it" meaning QDesktopServices.

    I looked the "File types" list on Windows and there wasn't anything assigned to the .exe files. So to test it I assigned a Hex Editor for handling the .exe files. It did the job as expected, opened .exe files with Hex Editor. But before I added the handler I noticed that there wasn't any special handler assigned to the .exe files but it was marked as "Type of File: Application" and I quess this is the reason why the Windows understands that the file is meant to be executed.

    So here I come back to the argument that if in unix system we have a file that hasn't got any handler assigned to it and it still has "execute" permissions allowed, why shouldn't it be launched by the QDesktopServices? Same manner as it is launched when you double click the icon on your file system.

    And these replies aren't meant for offence by any means, on the contrary. Just wanted to know about this issue which bothered me...

    -Tepi

Similar Threads

  1. Problems launching a windows exe from Qt (using QProcess)
    By smacchia in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2012, 10:05
  2. running external applications via QT?
    By cruisx in forum Newbie
    Replies: 1
    Last Post: 11th August 2009, 06:34
  3. Replies: 1
    Last Post: 1st December 2008, 21:02
  4. Replies: 7
    Last Post: 19th January 2008, 15:29
  5. Launching external web browser from within Qt App
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 18:22

Tags for this Thread

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.