PDA

View Full Version : QAxBase exception signal



thomas@itest
20th November 2013, 16:50
Hi all,

I'm using QAxBase objects (ms excel automation) and would like to connect the QAxBase::exception(int,QString,QString,QString) signal to manage errors but i can't ...

So, i've opened "qaxbase.h" source code and found :


#ifdef qdoc
Q_SIGNALS:
void signal(const QString&,int,void*);
void propertyChanged(const QString&);
void exception(int,const QString&,const QString&,const QString&);
#endif


of course "qdoc" is not defined ... so, what am i missing ?

I have hardly googled, read the docs, searched on this forum but i found nothing ...
(I think there's no link between the "#define qdoc" in the code and the "QDoc" html doc generator tool, so googling on qdoc is'nt an easy task but maybe i'm wrong)

I'm using qt4 (same results with 4.7.4 and 4.8.5)
I've put "CONFIG += qaxcontainer" in my pro file and nothing more.
My code compile and runs well ...

Please give me an answer even if its stupid (i'm really good at stupid mistakes ;) ) or a link to the answer i havn't been able to find.

thanks in advance

thomas@itest
25th November 2013, 17:04
a little up please ...

I don't find how to edit my post, so, i continue it
There's no answers, tell me if i'm doing anything wrong (am i violating forum rules ? maybe the bold text is provocating, i thought it would permit a faster read of my problem ... please just tell me)

Anyway, another formulation of my problem would be :

Why the signals of QAxBase object are declared within a "#ifdef qdoc" directive ?

thanks again

thomas@itest
11th December 2013, 11:38
another up ... (two weeks later, i can, can't i?)

ok, let's assume the exception signal is just a joke and just exists in documentation but not in the code !
it's just defined in qaxbase.h to generate documentation and make custommer trust active Qt is worth the bsd licence !

please tell me i'm wrong and criticize my disrespectful behavior !

ChrisW67
11th December 2013, 23:17
Your lack of response could be because few people use ActiveQt, and fewer have tried to use your particular corner of it.

Exactly how are you trying to connect?
Are the unspecified errors at compile, link, program run time, or during ActiveX operations?
What are the exact errors?
Can you post a complete, small example that demonstrates the problem?

thomas@itest
12th December 2013, 11:06
thank you so much for your answer !!!!


Your lack of response could be because few people use ActiveQt, and fewer have tried to use your particular corner of it.
I know that the good guys uses dumpcpptool. But, I'm not doing anything particular, just using a Qt class and connecting one of it signals to the slot of another Qt class ... nothing more than connecting the "clicked()" signal of a QPushButton ...


Exactly how are you trying to connect?
well, normally : connect(QAxObject *,SIGNAL(exception(int, QString, QString, QString), this, SLOT(myErrorHandleSlot(int, QString, QString, QString))
but when typing, the autocompletion didn't work, so, I checked my includes and includepath, .... everything were OK. So , at last, I've gone to the qaxbase.h source code and found the exception signal defined within an #ifdef qdoc preprocessor statement ... so, of course, i cannot connect. I could let this connect line code, it will compile but during runtime i'll get an error like "no such signal ..." (using Qt4)


Are the unspecified errors at compile, link, program run time, or during ActiveX operations?
What are the exact errors?
The errors are during ActiveX operations but are normal errors which can occur using excel, for instance, trying to write two cells within one, ...
my code compile and runs well, but, when an operation fails, an explicit message outputs on console and says "connect to the exception signal to retrieve these message"

As I can't connect to this signal, I just can know that the operation fails but not why and i can't show an explicit message to the user.


Can you post a complete, small example that demonstrates the problem?
Of course : http://www.itest.fr/Download/AxExcel.zip

The connection with exception signal is in xlapp.cpp file, line 38 :


XLApp::XLApp(QObject *parent) :
QObject(parent),
_xl(NULL),_workBooks(NULL)
{
_xl = new QAxWidget("Excel.Application");

// QObject::connect(_xl,SIGNAL(exception(int,QString, QString,QString)),
// this,SLOT(saveLastError(int,QString,QString,QStrin g)));

setVisible(false);
_workBooks = _xl->querySubObject("Workbooks");
}

Running the program should output an error message containing the informations of the exception signal i'd like to retrieve when executing the line 16 of main.cpp :


book->saveAs("Not*saveable");

it should ouput these wonderfull lines :
error code = 1004
Source = Microsoft Excel
Description = A really really good description but in french in my case ... (something like "file access error. Check the folder exists, ...")

thomas@itest
12th December 2013, 14:01
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

file 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

file main.cpp :

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

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
Connect to the exception(int,QString,QString,QString) signal to catch this exception

zhaolan94
24th September 2015, 14:09
damn...I hit the same problem to you.
Have you fixed it buddy?Could you mind telling me how to slove it?
thanks all...

thomas@itest
24th September 2015, 14:33
No, I gave up with Qt ActiveX !
Wrapping COM objects is not a huge work even if msdn documentation is a pain in the ...

mazhen2009
18th December 2017, 11:05
There is my code, It maybe help.


QAxObject* xlObj = new QAxObject("Excel.Application");

if (!xlObj->isNull())
{
xlObj->blockSignals(false);//<------- important
connect(xlObj, SIGNAL(signal(QString, int, void*)), SLOT(signal(QString, int, void*)));
}

In .h file

public Q_SLOTS:
void signal(const QString& name, int argc, void* argv);

in .cpp file


void XXXXX::signal(const QString& name, int argc, void* argv)
{
VARIANTARG *params = (VARIANTARG*)argv;
if (name.startsWith("BeforeNavigate2("))
{
IDispatch *pDisp = params[argc - 1].pdispVal;
VARIANTARG URL = *params[argc - 2].pvarVal;
VARIANTARG Flags = *params[argc - 3].pvarVal;
VARIANTARG TargetFrameName = *params[argc - 4].pvarVal;
VARIANTARG PostData = *params[argc - 5].pvarVal;
VARIANTARG Headers = *params[argc - 6].pvarVal;
bool *Cancel = params[argc - 7].pboolVal;
}
}