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



  • 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.



  • Can you show the code?

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



  • 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.



  • In your case app would be mWorddoc.

    where exactly do you get the error?



  • 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.



  • 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()@



  • 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!


Log in to reply
 

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