Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAxObject can not read from source.qrc
Qt 6.12 LTS is out! See what's new in the release blog

QAxObject can not read from source.qrc

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 375 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.
  • W Offline
    W Offline
    wuzhouquan
    wrote on last edited by
    #1

    Good day!i Try to Read template.docx in source.qrc,but there is an error ; If I read the absolute path, the program works fine.

    QAxBase: Error calling IDispatch member Add: Exception thrown by server
                 Code       : -2147467259
    

    Could you ,please , help me to solve this problem?
    here is my code

    void MainWindow::on_saveReport_clicked()
    {
        QString fileName = QFileDialog::getSaveFileName(this, tr("save report"),
                                                        "D:/Repoert.docx",
                                                        tr("Word Document (*.docx *.doc)"));
    
        if (true == fileName.isEmpty()){
            return;
        }
        QAxWidget *word = new QAxWidget("Word.Application", this, Qt::MSWindowsOwnDC);
        if(word->isNull()){
            QMessageBox::critical(this,tr("Critical"),tr("未安装office word"));
             return;
        }
        word->setProperty("DisplayAlerts", false);
        word->setProperty("Visible", false);
        QAxObject *documents = new QAxObject;
        documents = word->querySubObject("Documents");
    
        documents->dynamicCall("Add (QString)",  ":/template/reportTemplate.docx");
        QAxObject *readDocument = word->querySubObject("ActiveDocument");
    
        QAxObject *selection = readDocument->querySubObject("Content")->querySubObject("Find");
        bool bMatchCase      = false;
        bool bMatchWholeWord = false;
        bool bMatchWildCards = false;
        bool bReplaceAll     = true;
        QString flag1 = "txt1";
        QString target1 = "txt2";
        
        QVariantList vl = { flag1, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false, target1, bReplaceAll ? "2" : "1"};
        selection->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)",vl);
    
        //save
        readDocument->dynamicCall("SaveAs (const QString&)", fileName);
        readDocument->dynamicCall("Close (boolean)", false);
        word->dynamicCall("Quit(void)");
    }
    

    best regards,Quan

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • W wuzhouquan

      Good day!i Try to Read template.docx in source.qrc,but there is an error ; If I read the absolute path, the program works fine.

      QAxBase: Error calling IDispatch member Add: Exception thrown by server
                   Code       : -2147467259
      

      Could you ,please , help me to solve this problem?
      here is my code

      void MainWindow::on_saveReport_clicked()
      {
          QString fileName = QFileDialog::getSaveFileName(this, tr("save report"),
                                                          "D:/Repoert.docx",
                                                          tr("Word Document (*.docx *.doc)"));
      
          if (true == fileName.isEmpty()){
              return;
          }
          QAxWidget *word = new QAxWidget("Word.Application", this, Qt::MSWindowsOwnDC);
          if(word->isNull()){
              QMessageBox::critical(this,tr("Critical"),tr("未安装office word"));
               return;
          }
          word->setProperty("DisplayAlerts", false);
          word->setProperty("Visible", false);
          QAxObject *documents = new QAxObject;
          documents = word->querySubObject("Documents");
      
          documents->dynamicCall("Add (QString)",  ":/template/reportTemplate.docx");
          QAxObject *readDocument = word->querySubObject("ActiveDocument");
      
          QAxObject *selection = readDocument->querySubObject("Content")->querySubObject("Find");
          bool bMatchCase      = false;
          bool bMatchWholeWord = false;
          bool bMatchWildCards = false;
          bool bReplaceAll     = true;
          QString flag1 = "txt1";
          QString target1 = "txt2";
          
          QVariantList vl = { flag1, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false, target1, bReplaceAll ? "2" : "1"};
          selection->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)",vl);
      
          //save
          readDocument->dynamicCall("SaveAs (const QString&)", fileName);
          readDocument->dynamicCall("Close (boolean)", false);
          word->dynamicCall("Quit(void)");
      }
      

      best regards,Quan

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @wuzhouquan said in QAxObject can not read from source.qrc:

      Could you ,please , help me to solve this problem?

      I doubt a non Qt object (like your activeX object you're calling) can handle Qt resource paths. Copy it out from your resource to a directory and pass the path to the activeX object

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • W wuzhouquan

        Good day!i Try to Read template.docx in source.qrc,but there is an error ; If I read the absolute path, the program works fine.

        QAxBase: Error calling IDispatch member Add: Exception thrown by server
                     Code       : -2147467259
        

        Could you ,please , help me to solve this problem?
        here is my code

        void MainWindow::on_saveReport_clicked()
        {
            QString fileName = QFileDialog::getSaveFileName(this, tr("save report"),
                                                            "D:/Repoert.docx",
                                                            tr("Word Document (*.docx *.doc)"));
        
            if (true == fileName.isEmpty()){
                return;
            }
            QAxWidget *word = new QAxWidget("Word.Application", this, Qt::MSWindowsOwnDC);
            if(word->isNull()){
                QMessageBox::critical(this,tr("Critical"),tr("未安装office word"));
                 return;
            }
            word->setProperty("DisplayAlerts", false);
            word->setProperty("Visible", false);
            QAxObject *documents = new QAxObject;
            documents = word->querySubObject("Documents");
        
            documents->dynamicCall("Add (QString)",  ":/template/reportTemplate.docx");
            QAxObject *readDocument = word->querySubObject("ActiveDocument");
        
            QAxObject *selection = readDocument->querySubObject("Content")->querySubObject("Find");
            bool bMatchCase      = false;
            bool bMatchWholeWord = false;
            bool bMatchWildCards = false;
            bool bReplaceAll     = true;
            QString flag1 = "txt1";
            QString target1 = "txt2";
            
            QVariantList vl = { flag1, bMatchCase, bMatchWholeWord, bMatchWildCards, false, false, true, 1, false, target1, bReplaceAll ? "2" : "1"};
            selection->dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)",vl);
        
            //save
            readDocument->dynamicCall("SaveAs (const QString&)", fileName);
            readDocument->dynamicCall("Close (boolean)", false);
            word->dynamicCall("Quit(void)");
        }
        

        best regards,Quan

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @wuzhouquan said in QAxObject can not read from source.qrc:

        documents->dynamicCall("Add (QString)", ":/template/reportTemplate.docx");

        Do you have any evidence that documents->dynamicCall() can accept a Qt resource path? Remember, resource paths do not "exist" outside Qt, only Qt code can access them. I doubt Qt deals with this passing it to QAxObject code?

        @Christian-Ehrlicher's post has crossed with mine. You need to extract that resource to a physical, external file to make it acceptable.

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