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. [WORKED AROUND]QAxObject ,how do I get access to Subobjects?
QtWS25 Last Chance

[WORKED AROUND]QAxObject ,how do I get access to Subobjects?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 3.4k 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi,
    I am trying to open MS office files in my application,but when opened I want to have access to some of the document internal details.I know of the generateDocumentation () method to see what I can call on the object,but how do I know the subobjects an object have?

    For example we have such a syntax to get the number of pages in a word document[from msdn]:

    @

    ActiveDocument.Range.Information(wdNumberOfPagesInDocument)

    @

    The idea is to know which subobjects my defined object has,so I can run generateDocumentation on them to get access to the information I need.I would be glad if somebody helped with this.

    EDIT:Every time I try to run querrySubObject using the names I get from the msdn doc,I get "Unkown object" Errors.

    Thanks.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chris17
      wrote on last edited by
      #2

      Can you show the code?

      Should work like this:
      @
      QAxobject *activeDoc=app.querySubobject("ActiveDocument");
      QAxobject *range=activeDoc.querySubobject("Range");
      QAxobject *activeDoc=range.dynamicCall(...);
      @

      1 Reply Last reply
      0
      • musimbateM Offline
        musimbateM Offline
        musimbate
        wrote on last edited by
        #3

        Thanks chris17 for the reply,
        What does app stand for in your code?following is a simplified version of all the relevant code:

        @

        Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
        {
        ui->setupUi(this);
        //CUSTOM STUFF

        //I create a word object like this
         mWordDoc=new CustomQAxWidget("d:\\gakwandi.docx",0);
        QAxObject *activeDoc=mWordDoc->querySubObject("ActiveDocument");
           QAxObject *range=activeDoc->querySubObject("Range");
        int NumberOfPages=range->dynamicCall("Information(wdNumberOfPagesInDocument)").toInt();
        
        //this is a dummy size I passed just to see that my document shows properly.
        mWordDoc-> setMinimumSize(800,4000);
        
        QScrollArea * scrollArea=new QScrollArea;
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidget(mWordDoc);
        
        QVBoxLayout * layout=new QVBoxLayout();
        layout->setSizeConstraint(QLayout::SetNoConstraint);
        layout->addWidget(scrollArea);
        setLayout(layout);
        

        resize(mWordDoc->width()+10,500);
        }

        @

        I need to retrieve the number of pages so I can use it to compute the minimum size to pass to setMinimumSize( );This allows the scrollArea to have an idea of the whole document.
        Is this a good way to go about it?

        Thanks again for your time.

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chris17
          wrote on last edited by
          #4

          In your case app would be mWorddoc.

          where exactly do you get the error?

          1 Reply Last reply
          0
          • musimbateM Offline
            musimbateM Offline
            musimbate
            wrote on last edited by
            #5

            Thanks again for the reply,
            The application simply crashes and exits when I run it
            I am getting the following error when I run the application.

            Starting E:\TestQtApps\pimaAXWIDGET\debug\pimaAXWIDGET.exe...
            QAxBase::dynamicCallHelper: ActiveDocument: No such property in d:\gakwandi.docx [unknown]
            Candidates are:
            The program has unexpectedly finished.

            Is there any other configuration that is needed to get this to work?I have this line in my pro file
            @

            CONFIG += qaxcontainer

            @

            and have included the relevant headers to the files.May be the properties I am trying to access are not correct?
            Thanks.

            Why join the navy if you can be a pirate?-Steve Jobs

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chris17
              wrote on last edited by
              #6

              Use the debugger to see at which line the crash occurs.

              You should also check if the instantiated QAxObjects are valid.
              i.e. @mWordDoc->isNull()@

              1 Reply Last reply
              0
              • musimbateM Offline
                musimbateM Offline
                musimbate
                wrote on last edited by
                #7

                I could finally get it to work,and I am leaving the solution here in case someone else needs it:

                Note that this is a workaround:

                I needed 2 things : 1.Displaying an instance of a word application in a widget (which QAxWidget is does) and 2. retreive the number of pages in the document I am displaying.
                But surprisingly enough, QAxWidget was always rejecting my querrySubObject calls .Later i found out that QAxObject was taking them.So I had no choice but to use QAxObject to retrieve the number and QAxWidget to do my displaying. This is illogical as one QAxWidget should do the job but it is the best option I got.Here is the code:

                @

                //1.CREATE A WORD APPLICATION INSTANCE
                QAxObject* word = new QAxObject("Word.Application", this);

                // word->setProperty("Visible",false);
                //2.OPEN THE DOCUMENT
                QAxObject* doc = word->querySubObject("Documents");
                doc->dynamicCall("Open(QVariant)", wordFilename);
                doc->setProperty("Visible",false);
                //3.GET TO THE CONTENTS
                QAxObject * activeDocument=word->querySubObject("ActiveDocument");

                QAxObject * content=activeDocument->querySubObject("Content");
                
                int mNumberOfPages = content->dynamicCall("Information(wdNumberOfPagesInDocument)").toInt();
                
                doc->dynamicCall("Close (boolean)", false);
                word->dynamicCall("Quit (void)");
                

                @

                I also got helpful hints from "here":http://stackoverflow.com/questions/19264120/qt-activex-retrieving-the-number-of-pages-in-a-word-document/19309609#19309609

                Hope this comes in helpful someday.
                Happy coding!

                Why join the navy if you can be a pirate?-Steve Jobs

                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