Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]MS Word file - PrintOut method
QtWS25 Last Chance

[SOLVED]MS Word file - PrintOut method

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 3 Offline
    3 Offline
    3lias
    wrote on last edited by
    #1

    Hello everyone, i'm back again with an new question.

    I want to print a word file that i have opened in word from my code.I found out that the method i have to use is "PrintOut" but i cannot found anywhere an example on how can i use it.

    All i need is a very simple example just to under--stand the way it works.

    Any help is appreciated

    PS: the code i use to open the file is
    @
    word = new QAxWidget(this);
    word->setControl("Word.Application");
    word->dynamicCall("Visible", true );
    QAxObject* docs = word->querySubObject( "Documents" );
    QVariant filename("d:/a.docx");
    QVariant confirmconversions(false);
    QVariant readonly(true);
    QVariant addtorecentfiles(false);
    QVariant passworddocument("");
    QVariant passwordtemplate("");
    QVariant revert(false);
    QVariant background(false);
    QVariant append(false);
    QAxObject* doc = docs->querySubObject("Open(const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&, const QVariant&,const QVariant&)", filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert);
    QAxObject* print = docs->querySubObject("PrintOut(const QVariant&,const QVariant&)", background , append);
    @

    the last line is not working :'(

    Thank you
    3lias

    1 Reply Last reply
    0
    • 3 Offline
      3 Offline
      3lias
      wrote on last edited by
      #2

      My mistake was on the paremeters i used.It doesn't need them.The only thing i have to write was
      @
      QAxWidget doc->querySubObject("PrintOut()");
      @
      :)
      3lias

      1 Reply Last reply
      0
      • B Offline
        B Offline
        barisatamer
        wrote on last edited by
        #3

        I want the document to stay in my main window. So my code for opening the document:

        @ WordDocument=new QAxWidget ("Word.Document", this-> ui-> centralWidget);

        WordDocument-> setGeometry (QRect (10, 10, 621, 471));
        WordDocument-> setControl ("D:/c.docx");
        
        WordDocument-> show ();
        

        @

        And I have a PushButton for printing :
        @
        void MainWindow::on_printButton_clicked()
        {
        WordDocument->querySubObject("PrintOut()");
        }
        @

        It works perfectly unless I modify the document. If I type something to the document, and try to print it gives these errors :
        QAxBase: Error calling IDispatch member PrintOut: Exception thrown by server

                 Code       : 4605
        
                 Source     : Microsoft Word
        
                 Description: Bu y?ntem veya ?zellik kullan?lamaz. ??nk? bu belge, ba?ka bir uygulama program? taraf?ndan d?zenleniyor. (meaning: this method or property could not be used, other application is editing ...)
        
                 Help       : C:\Program Files\Microsoft Office\Office12\1055\WDMAIN11.CHM [37373]
        
             Connect to the exception(int,QString,QString,QString) signal to catch this exception
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved