[ActiveQT] Why does it work that way?



  • Hi all,
    I had a problem with reading data from a table inside a Word document. I eventually resolved it, but now I have a question about the code style for dynamicCall

    Here's my code that works just fine:
    @QAxObject *wordApp = new QAxObject("Word.Application");
    QAxObject *allDocs = wordApp->querySubObject("Documents()");
    allDocs->dynamicCall("Open(const QString&)", "C:\mydocument.doc");

    QAxObject *currentDoc = wordApp->querySubObject("ActiveDocument");
    currentDoc->querySubObject("ActiveWindow()")->querySubObject("Selection()")->querySubObject("GoTo(wdGoToTable,wdGoToFirst,1,"")");
    currentDoc->querySubObject("ActiveWindow()")->querySubObject("Selection()")->dynamicCall("SelectCell()");
    QString cellText = currentDoc->querySubObject("ActiveWindow()")->querySubObject("Selection()")->dynamicCall("Text()").toString();@

    The line in question is #6. Initially, I tried to write it the same way as the Open() dynamic call, i.e:

    @currentDoc->querySubObject("ActiveWindow()")->querySubObject("Selection()")->querySubObject("GoTo(const QString&,const QString&,int,const QString&)", QString("wdGoToTable"), QString("wdGoToFirst"), 1, QString(""));@

    as well as this way
    @
    QList<QVariant> goToTable;
    goToTable.append(QVariant(QString("wdGoToTable")));
    goToTable.append(QVariant(QString("wdGoToNext")));
    currentDoc->querySubObject("ActiveWindow()")->querySubObject("Selection()")->querySubObject("GoTo(QList<QVariant>&)", goToTable);@

    I also tried replacing wdGoToTable and wdGoToFirst with their respective enum values.

    Still, in any of those cases I got:

    @QAxBase: Error calling IDispatch member GoTo: Exception thrown by server
    Code : 4120
    Source : Microsoft Word
    Description: Bad parameter@

    Which was gone only after I wrote the GoTo with parameters right in the string and instead of passing them as parameters.
    The documentation for ActiveQt of Qt 5.1 (which I am using) says I can write this both ways (I checked it for the Open() function and it worked). I am glad that I figured out how to bypass the error, but the documentation says:

    bq. Alternatively a function can be called passing the parameters embedded in the string, e.g. above function can also be invoked using
    All parameters are passed as strings; it depends on the control whether they are interpreted correctly, and is slower than using the prototype with correctly typed parameters.

    I don't like the word "slower" in this paragraph, so I would really love to know how to make Selection.GoTo work with parameters the same way Open() does.

    Thanks,
    Max


Log in to reply
 

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