[SOLVED] Handling COM event Qt/C++
-
I didn't try connecting to Event for Excel but for Word and I found out that I could only connect to Events which have no parameters like 'DocumentChange()'. I use the tool 'dumpcpp.exe' from ActiveQt and generated wrapper classes for Word, but handling events was only possible via the generic signal
@signal(QString,int,void*)@I don't know why it didn't work but there are different Event signatures.
I want to show an example:
First of all, I connect to the generic signal 'signal(QString,int,void*)' to handle all event. In the first param (QString), you find the name of the event with full signature. In case of word, there is e.g. an event called
@DocumentBeforeClose(IDispatch*,bool&)@
If i directly connect to that signal...
@connect(word, SIGNAL(DocumentBeforeClose(IDispatch*,bool&)), this, SLOT(onDocumentBeforeClose(IDispatch*,bool&)));@
...I get a message:
Object::connect: No such signal Word::Application::DocumentBeforeClose(IDispatch*,bool&)
I studied the generated code of the word wrapper classes and I found in the metadata string, that the signature is:
@DocumentBeforeClose(Document*,bool&)@
The same signature is printed out if I use the code from Maxbester to show all signals. If I connect to this event, there is no output on console (no error message) so I thought this is the correct event, but my slot is never called (it has no parameter just to make sure that there are no problems due to paramter conversion, etc)
@connect(word, SIGNAL(DocumentBeforeClose(Document*,bool&)), this, SLOT(onDocumentBeforeClose()));@
By the way, all word events are fired 2 to 4 times (http://qt-project.org/forums/viewthread/38109), so I think there are either bugs in ActiveQt event handling or there is a trick how to do it?!?!
-
There may be some bugs indeed.
In the .pro file I added:
@TYPELIBS = $$system( dumpcpp lib/MyLib.tlb -n MyNameSpace -o src/MyActiveXClass )@
Note that the -o is important. It was missing in my first tries. This option writes the class declaration to MyActiveXClass.h and meta object infomation to MyActiveXClass.cpp.
Maybe it will help you.