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. [ActiveQT] Why does it work that way?

[ActiveQT] Why does it work that way?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    breln
    wrote on last edited by
    #1

    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

    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