Вопрос

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