Pregunta

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

¿Fue útil?

Solución

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 &)));
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top