Sorry, i should have made a really simpler example (still complete and compilable):
project file, let's say "AxExcel.pro"
QT += core gui
TARGET = TestAxExcel
TEMPLATE = app
CONFIG += qaxcontainer
SOURCES += main.cpp
HEADERS += exceptreceiver.h
QT += core gui
TARGET = TestAxExcel
TEMPLATE = app
CONFIG += qaxcontainer
SOURCES += main.cpp
HEADERS += exceptreceiver.h
To copy to clipboard, switch view to plain text mode
file exceptreceiver.h :
#ifndef EXCEPTRECEIVER_H
#define EXCEPTRECEIVER_H
#include <QObject>
#include <QDebug>
class ExceptReceiver
: public QObject{
Q_OBJECT
public:
public slots:
{
qDebug()<<errorCode<<source<<description<<help;
}
};
#endif // EXCEPTRECEIVER_H
#ifndef EXCEPTRECEIVER_H
#define EXCEPTRECEIVER_H
#include <QObject>
#include <QDebug>
class ExceptReceiver : public QObject
{
Q_OBJECT
public:
ExceptReceiver():QObject(){}
public slots:
void debugError(int errorCode, QString source, QString description, QString help)
{
qDebug()<<errorCode<<source<<description<<help;
}
};
#endif // EXCEPTRECEIVER_H
To copy to clipboard, switch view to plain text mode
file main.cpp :
#include <QApplication>
#include <QAxObject>
#include "exceptreceiver.h"
int main(int argc, char *argv[])
{
ExceptReceiver er;
if(QAxObject *wbs
= xlObj.
querySubObject("Workbooks")) {
if(QAxObject *workbook
= wbs
->querySubObject
("Add()")) {
workbook->dynamicCall("SaveAs(const QString &)","not*saveable");
delete workbook;
}
delete wbs;
}
return 0;
}
#include <QApplication>
#include <QAxObject>
#include "exceptreceiver.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QAxObject xlObj("Excel.Application");
ExceptReceiver er;
QObject::connect(&xlObj,SIGNAL(exception(int, QString, QString, QString)),
&er,SLOT(debugError(int,QString,QString,QString)));
if(QAxObject *wbs = xlObj.querySubObject("Workbooks"))
{
if(QAxObject *workbook = wbs->querySubObject("Add()"))
{
workbook->dynamicCall("SaveAs(const QString &)","not*saveable");
delete workbook;
}
delete wbs;
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Console output when running this program (in french but it shouldn't be important) :
QAxBase: Error calling IDispatch member SaveAs
: Exception thrown by server
Code : 1004
Source : Microsoft Excel
Description: Fichier inaccessible. Essayez l'une des op?rations suivantes?:
? V?rifiez que le dossier sp?cifi? existe.
? V?rifiez que le dossier dans lequel se trouve le fichier n'est pas en lecture seule.
? V?rifiez que le nom du fichier ne comporte les caract?res suivants: | < > ? [ ] : ni *
? V?rifiez que le nom du fichier ou du chemin ne d?passe pas 218 caract?res.
Help : xlmain11.chm
QAxBase: Error calling IDispatch member SaveAs: Exception thrown by server
Code : 1004
Source : Microsoft Excel
Description: Fichier inaccessible. Essayez l'une des op?rations suivantes?:
? V?rifiez que le dossier sp?cifi? existe.
? V?rifiez que le dossier dans lequel se trouve le fichier n'est pas en lecture seule.
? V?rifiez que le nom du fichier ne comporte les caract?res suivants: | < > ? [ ] : ni *
? V?rifiez que le nom du fichier ou du chemin ne d?passe pas 218 caract?res.
Help : xlmain11.chm
Connect to the exception(int,QString,QString,QString) signal to catch this exception
To copy to clipboard, switch view to plain text mode
Bookmarks