2013-10-18 56 views
0

我想用QAxObject来处理Excel文件。
我想以某种方式实现初始化像下面的代码:如何用QAxObject捕捉/抛出错误

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 /抛出错误?我试图谷歌它,但没有发现任何exapmlpe

回答

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 &))); 
} 
+0

谢谢,乡下人! :)我会在稍后接受你的回答,好吗?恐怕今天我还有其他的东西,明天我会检查你的灵魂 – DanilGholtsman