原文地址::https://www.e-learn.cn/topic/3633655

相关文章

1、Qt使用QAxObject操作Excel,在线程中调用失败解决办法----http://www.myexceptions.net/qt/396358.html

2、QT调用COM组件----https://blog.csdn.net/yedehei_lt/article/details/49974321

3、QT在子线程中使用QAxWidget需要初始化COM的问题----https://blog.csdn.net/a1069962325/article/details/48975179?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control

4、Qt 下的COM组件开发----https://blog.csdn.net/jx1228/article/details/7065474?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-1&spm=1001.2101.3001.4242

5、Qt调用COM组件 笔记----https://blog.csdn.net/cibiren2011/article/details/78660050?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control

 

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]

 

来源:https://www.cnblogs.com/azbane/p/12780398.html

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐