QAxObject can not read from source.qrc
-
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 : -2147467259Could you ,please , help me to solve this problem?
here is my codevoid 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
-
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 : -2147467259Could you ,please , help me to solve this problem?
here is my codevoid 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
@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
-
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 : -2147467259Could you ,please , help me to solve this problem?
here is my codevoid 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
@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 toQAxObjectcode?@Christian-Ehrlicher's post has crossed with mine. You need to extract that resource to a physical, external file to make it acceptable.