[Solved] Invoking external applications to view, edit and print documents



  • I was wondering what the portable Qt way (if there is one) of invoking external applications to view, edit or print arbitrary documents would be?
    I have the quite common problem that from within a Qt application I need to view, edit or print documents with the appropriate applications for each of the supported the platforms. Before using Qt this was done with (quite some) platform specific code and I would like to reduce this as much as possible.
    I had a look at QDesktopServices:: openUrl and it seems to handle the view operations quite well but printing and editing would not be covered.
    Especially the edit operations are a bit more complicated because they need to keep track of when the process ends.
    Thank you for your advice!



  • QDesktopServices::openUrl() does the bulk work for you when you want to open stuff in external applications. However, when you want to know when the used process is finished, you'll probably have to write your own implementation using QProcess. I'm afraid that will involve some platform specifics to find out which program is associated with your file.



  • [quote author="Franzk" date="1290671318"]QDesktopServices::openUrl() does the bulk work for you when you want to open stuff in external applications. However, when you want to know when the used process is finished, you'll probably have to write your own implementation using QProcess. I'm afraid that will involve some platform specifics to find out which program is associated with your file.[/quote]

    1. Would openUrl also be able to do the printing?
    2. Are the any examples on how to use QProcess for this?


  • [quote author="d.oberkofler" date="1290678246"]

    1. Would openUrl also be able to do the printing?
    2. Are the any examples on how to use QProcess for this?
      [/quote]

    openUrl does not handle printing. This would be highly platform and application dependent.

    There are some uses of QProcess in
    help/remotecontrol
    help/simpletextviewer
    dbus/complexpingpong
    in the Qt sources. The API docs of "QProcess":http://doc.qt.nokia.com/4.7/qprocess.html are alos quite useful.



  • With QProcess I can indeed start e.g. an editor, even with command arguments to start the editor and go to a specific line. I should like to open the editor in a subwindow of the application (QMdiArea), and not a detached one. Is that possible?



  • You can't put an external App in a sub window...
    Windows of executable are always top level windows, especially as the processes have seperated areas of memory. But if you need an editor and a sub window, why donÄt you use QTextEdit?



  • Thanks for the explanation. I now use QPlainTextEdit, and that is great. It is, however, some work to add all features you expect from an editor and I should like to give the users of my application the possibility to use the editor of their own choice.



  • Then you can't use the window as child window. Then Its always a seperate process with own top level windows.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.