Qt 使用QAxObject 访问 Word 异常问题 --- 持续更新中
1、
CoCreateInstance failure (尚未调用CoInitialize。)
QAxbase::dynamicCallHelper: Object is not initialized, or initialization failed.
添加 OleInitialize的调用 HRESULT result = OleInitialize(nullptr); //换成CoInitialize似乎也是一样的 if (result != S_OK && result != S_FALSE) { qDebug()<<QString("Could not initialize OLE (error %x)").arg(static_cast<unsigned int>(result)); } m_pWord = new QAxObject(); bool bFlag = m_pWord->setControl( "word.Application" );
2、QAxBase: Error calling IDispatch member Add: Exception thrown by server
Code : -2146823114
Source :Microsoft Word
Description :?????????????????????
Help :wdmain11.chm[24654]
Connect to the exception<int, QString, QString, Qstring> signal to catch this exception
QAxBase: Error calling IDispatch member ActiveDocument: Exception thrown by server
Code : -2146824040
Source :Microsoft Word
Description :?????????????????????
Help :wdmain11.chm[37016]
Connect to the exception<int, QString, QString, Qstring> signal to catch this exception
QAxBase:: Signals: exception(int code, const QString &source, const QString &desc, const QString &help)
根据提示,捕获异常 //.h public slots: void slots_exception(/*int a, QString b, QString c, QString d*/); //usecase connect(m_pWord, SIGNAL(exception(int, QString, QString, QString)), this, SLOT(slots_exception())); 这里有两个注意点: a-QAxObject从QAxBase继承来的信号,不能用最新版函数指针版connect,只能使用旧版的宏字符串版本connect。 b-旧版的宏字符串版本的connect关联的槽函数,必须是"访问修饰符+slots:"声明的槽函数。 否则会报错No Such slots。 我们知道,新版函数指针的版的connect,槽函数可以是普通的成员函数。
-2146823114 "Mircosoft Word" 抱歉, 找不到您的文件。是否可能被移动、重命名或删除? wdmain11.chm [24654]
-2146824040 "Mircosoft Word" 因为没有打开的文档,所以这一命令无效。 wdmain11.chm [37016]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架