0

我想使用QAxObjectExcel 文件。
我想以某种方式实现初始化,如下面的代码:

QAxObject* excel;//excel pointer

void initExcel(){
    try
    {
        //if there excel process already running try to use it
    }
    //catch if it's not running
    catch()
    {
        try 
        {
            excel = new QAxObject("Excel.Application");
        } 
        catch 
        {
            //meassge if excel not exist/can't start     
        }
    }
}

如何使用 QAxObject 捕获/抛出错误?我试图用谷歌搜索,但没有找到任何示例

4

1 回答 1

2

要知道是否加载了 ActiveX 控件,您应该使用 setControl 方法的结果。要捕获 ActiveX 控件的异常,您应该连接到异常信号。

bool controlLoaded = axWidget->setControl("Word.Document");
if (!controlLoaded)
{
    // Message about control didn't load
}
else
{
    // Control loaded OK; connecting to catch exceptions from control
    connect(
        axWidget, 
        SIGNAL(exception(int, const QString &, const QString &, const QString &)), 
        this, 
        SLOT(onAxWidgetException(int, const QString &, const QString &, const QString &)));
}
于 2013-10-18T12:31:40.140 回答