<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QAxObject can not read from source.qrc]]></title><description><![CDATA[<p dir="auto">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.</p>
<pre><code>QAxBase: Error calling IDispatch member Add: Exception thrown by server
             Code       : -2147467259
</code></pre>
<p dir="auto">Could you ,please , help me to solve this problem?<br />
here is my code</p>
<pre><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-&gt;isNull()){
        QMessageBox::critical(this,tr("Critical"),tr("未安装office word"));
         return;
    }
    word-&gt;setProperty("DisplayAlerts", false);
    word-&gt;setProperty("Visible", false);
    QAxObject *documents = new QAxObject;
    documents = word-&gt;querySubObject("Documents");

    documents-&gt;dynamicCall("Add (QString)",  ":/template/reportTemplate.docx");
    QAxObject *readDocument = word-&gt;querySubObject("ActiveDocument");

    QAxObject *selection = readDocument-&gt;querySubObject("Content")-&gt;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-&gt;dynamicCall("Execute(QString,bool,bool,bool,bool,bool,bool,int,bool,QString,int)",vl);

    //save
    readDocument-&gt;dynamicCall("SaveAs (const QString&amp;)", fileName);
    readDocument-&gt;dynamicCall("Close (boolean)", false);
    word-&gt;dynamicCall("Quit(void)");
}
</code></pre>
<p dir="auto">best regards,Quan</p>
]]></description><link>https://forum.qt.io/topic/145980/qaxobject-can-not-read-from-source-qrc</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 05:00:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145980.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Jun 2023 09:19:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QAxObject can not read from source.qrc on Sun, 25 Jun 2023 09:35:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wuzhouquan">@<bdi>wuzhouquan</bdi></a> said in <a href="/post/762546">QAxObject can not read from source.qrc</a>:</p>
<blockquote>
<p dir="auto"><code>documents-&gt;dynamicCall("Add (QString)",  ":/template/reportTemplate.docx");</code></p>
</blockquote>
<p dir="auto">Do you have any evidence that <code>documents-&gt;dynamicCall()</code> can accept a Qt resource path?  Remember, resource paths do not "exist" outside Qt, <em>only</em> Qt code can access them.  I doubt Qt deals with this passing it to <code>QAxObject</code> code?</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a>'s post has crossed with mine.  You need to extract that resource to a physical, external file to make it acceptable.</p>
]]></description><link>https://forum.qt.io/post/762548</link><guid isPermaLink="true">https://forum.qt.io/post/762548</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 25 Jun 2023 09:35:27 GMT</pubDate></item><item><title><![CDATA[Reply to QAxObject can not read from source.qrc on Sun, 25 Jun 2023 09:33:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wuzhouquan">@<bdi>wuzhouquan</bdi></a> said in <a href="/post/762546">QAxObject can not read from source.qrc</a>:</p>
<blockquote>
<p dir="auto">Could you ,please , help me to solve this problem?</p>
</blockquote>
<p dir="auto">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</p>
]]></description><link>https://forum.qt.io/post/762547</link><guid isPermaLink="true">https://forum.qt.io/post/762547</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 25 Jun 2023 09:33:58 GMT</pubDate></item></channel></rss>