Results 1 to 12 of 12

Thread: How to call WinWord.exe through the Qt program?

  1. #1
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question How to call WinWord.exe through the Qt program?

    On the window platform, On the assumption that the user don't know the MS word install path, I want to call the winword.exe to open a defaut doc file such as E:/test.doc through the Qt program. The Qt provide a QProcess class to start external programs, but I don't know how to use them. the following is my code, it does not work! Does anyone has some idea? thank you!

    Qt Code:
    1. QProcess* por = new QProcess(this);
    2. lst.append(tr("E:/test.doc"));
    3. por->start(tr("WinWord.exe"),lst);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to call WinWord.exe through the Qt program?

    what for are you use QObject::tr() function?
    east or west home is best

  3. #3
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to call WinWord.exe through the Qt program?

    and if you write simply WinWord.exe the path that contains this file(WinWord.exe) must be add in a system path.
    east or west home is best

  4. #4
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to call WinWord.exe through the Qt program?

    You are right, if I use the absolute path, the pragram will work. However, I don't want to use absolute path because the pragram don't know the install path of MS word when running on different machines.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to call WinWord.exe through the Qt program?

    Quote Originally Posted by bangqianchen View Post
    However, I don't want to use absolute path because the pragram don't know the install path of MS word when running on different machines.
    But you have to. Possible solutions:
    • create a configure dialog where the user can define the path to the program
    • create a list of possible locations and check if one of them is valid and then use that path. (use QFile::exists() and may be QDesktopServices::ApplicationsLocation will help you also)
    • Use Windows api (but don't me about that...)

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to call WinWord.exe through the Qt program?

    may be QDesktopServices::openUrl will help?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    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 call WinWord.exe through the Qt program?

    You can also use QCoreSettings with Native Format to read the windows registry in which the location of Office is stored. You can also get the version that way too if you wanted to show it to the user.

  8. #8
    Join Date
    Aug 2008
    Posts
    33
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to call WinWord.exe through the Qt program?

    I am out of office for a few days, and I think read the windows registry may be is better, thank you , I will try!

  9. #9
    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: How to call WinWord.exe through the Qt program?

    Better than using QDesktopServices::openUrl()? I don't think so...
    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.


  10. #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 call WinWord.exe through the Qt program?

    Most certainly, openUrl should work on Windows, Mac & Linux, whereas registry approach is Windows specific.

    If you don't care your program is Windows specific, then can even use OLE:

    Variant MSWord;
    MSWord = CreateOleObject("Word.Basic");
    MSWord.Exec(Procedure("AppShow"));
    MSWord.Exec(Procedure("FileNew") << "Normal");
    MSWord.Exec(Procedure("Insert") << "Hello World!");

    This way uses an existing instance if available, or loads the application if it's not already running.

  11. #11

    Default Re: How to call WinWord.exe through the Qt program? [where is QCoreSettings?]

    Where can I find QCoreSettings? I have downloaded latest Qt open source and commercial versions (trial) but QCoreSettings is not there.

  12. #12
    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: How to call WinWord.exe through the Qt program? [where is QCoreSettings?]

    There is no such class in Qt. It's QSettings.
    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.


Similar Threads

  1. Segmentation Fault when Program Starts
    By KaptainKarl in forum Newbie
    Replies: 7
    Last Post: 10th September 2009, 08:43
  2. External Program Management with Qt
    By rapajic in forum Qt Programming
    Replies: 5
    Last Post: 7th April 2009, 09:52
  3. Eclipse Integration and program not starting
    By Cruz in forum Installation and Deployment
    Replies: 1
    Last Post: 16th January 2009, 22:32
  4. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  5. call bash/terminal command with QT
    By myta212 in forum Newbie
    Replies: 1
    Last Post: 13th November 2006, 15:38

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.