zoukankan      html  css  js  c++  java
  • 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]
  • 相关阅读:
    Nginx快速自查手册
    python——常见排序算法解析
    config、option、setting辨析
    python——append与extend
    crm——stark组件核心原理
    码,码,码不停!
    python——设计模式
    CCI_chapter 4 trees and Grapths
    题目1509:树中两个结点的最低公共祖先
    CCI_chapter 3 Stacks and Queues
  • 原文地址:https://www.cnblogs.com/azbane/p/12780398.html
Copyright © 2011-2022 走看看