문제

I want use QAxObject to work with Excel files.
I want implement initialization somehow like following code:

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     
        }
    }
}

How could I catch/throw errors with QAxObject? I tried to google it but didn't found any exapmlpe

도움이 되었습니까?

해결책

To know if ActiveX control loaded, you should use the result of setControl method. To catch ActiveX control's exceptions, you should connect to exception signal.

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 &)));
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top