Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Handling COM event Qt/C++
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Handling COM event Qt/C++

Scheduled Pinned Locked Moved General and Desktop
22 Posts 4 Posters 12.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maxbester
    wrote on last edited by
    #12

    Al right, this is not a bad idea. I am going to try that.
    Thanks!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #13

      Hi Maxbester,

      to read the content of a Tlb (or a OCM dll, ocx file) you can use Oleview from Microsoft.
      It extracts all information of a type library.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Maxbester
        wrote on last edited by
        #14

        It doesn't seem to work. I've got the message:
        @
        QObject::connect: No such signal QAxBase::INotify2(...)
        @

        I found a document about the software I try to interact with. It is "Pulse Labshop":http://homel.vsb.cz/~tum52/download/PULSEAutomation.pdf from "Brüel & Kjaer":http://www.bksv.com.

        This link leads to a pdf with some basic information. Page 56 is an explanation about how to work with its notification system (to me, it just looks like events).

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #15

          INotify2 doesn't look like the actual name of the event. However, what you could try is to use QMetaObject to just list the signals from your QAxObject at runtime.

          @
          const QMetaObject* mo = myQAxObject->metaObject();
          int i(0);
          while (i < mo->methodCount()) {
          QMetaMethod mm = mo->metaMethod(i++);

          QString typeString;
          switch (mm.type()) {
          case QMetaMethod::Method: typeString = QString("Method"); break;
          case QMetaMethod::Signal: typeString = QString("Signal"); break;
          case QMetaMethod::Slot: typeString = QString("Slot"); break;
          case QMetaMethod::Constructor: typeString = QString("Constructor"); break;
          }

          QString accessString;
          switch (mm.access()) {
          case QMetaMethod::Private: typeString = QString("Private"); break;
          case QMetaMethod::Protected: typeString = QString("Protected"); break;
          case QMetaMethod::Public: typeString = QString("Public"); break;
          }

          qDebug() << accessString << typeString << mm.signature();
          }
          @

          Something like the above can be used to get a good view of all the methods, signals and slots of your object. It should also list any dynamically generated ones, if there are any. Perhaps you can use it to find out the exact signature of the signals you're after, instead of guessing what they might be called and what arguments you need for them...

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Maxbester
            wrote on last edited by
            #16

            Thanks a lot! I didn't know a such thing was possible.

            I changed a little bit your code because there are some mistakes:

            @
            PulseLabShop::IPulseLabShop2* app = new PulseLabShop::IPulseLabShop2();
            const QMetaObject* mo = app->metaObject();
            for (int i=0; i<mo->methodCount(); i++) {
            QMetaMethod mm = mo->method(i);

              QString typeString;
              switch (mm.methodType()) {
              case QMetaMethod::Method: typeString = QString("Method"); break;
              case QMetaMethod::Signal: typeString = QString("Signal"); break;
              case QMetaMethod::Slot: typeString = QString("Slot"); break;
              case QMetaMethod::Constructor: typeString = QString("Constructor"); break;
              }
            
              QString accessString;
              switch (mm.access()) {
              case QMetaMethod::Private: typeString = QString("Private"); break;
              case QMetaMethod::Protected: typeString = QString("Protected"); break;
              case QMetaMethod::Public: typeString = QString("Public"); break;
              }
            
              qDebug() << accessString << typeString << mm.signature();
            }
            

            @

            I found one signal for this class. I will try to connect it.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Maxbester
              wrote on last edited by
              #17

              Finally, all classes and interfaces return the same signals and slots:

              @
              "Protected" "signal" destroyed(QObject*)
              "Protected" "signal" destroyed()
              "Public" "slot" deleteLater()
              "Public" "slot" _q_reregisterTimers(void*)
              "Protected" "signal" signal(QString,int,void*)
              "Protected" "signal" propertyChanged(QString)
              "Protected" "signal" exception(int,QString,QString,QString)
              @

              I cannot connect a protected signal. I am still stuck... Any idea?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #18

                All of these are standard QObject signals and slots, nothing specific to QAxObject. Are you sure the QAxObject is properly initialized before you do this? That is, that it represents a valid COM object? If so, then I have no clue, and I am afraid I led you down a dead end. My apologies for that.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Maxbester
                  wrote on last edited by
                  #19

                  [quote author="Andre" date="1360050606"]Are you sure the QAxObject is properly initialized before you do this?[/quote]

                  It should be. However, the program license may be expired. I have to work on this and try to reinstall Pulse Labshop.
                  I will come back here after.

                  Anyway, thanks for your help ;)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Maxbester
                    wrote on last edited by
                    #20

                    [quote author="Maxbester" date="1359997679"]Thanks a lot! I didn't know a such thing was possible.

                    I changed a little bit your code because there are some mistakes:

                    @
                    PulseLabShop::IPulseLabShop2* app = new PulseLabShop::IPulseLabShop2();
                    const QMetaObject* mo = app->metaObject();
                    for (int i=0; i<mo->methodCount(); i++) {
                    QMetaMethod mm = mo->method(i);

                      QString typeString;
                      switch (mm.methodType()) {
                      case QMetaMethod::Method: typeString = QString("Method"); break;
                      case QMetaMethod::Signal: typeString = QString("Signal"); break;
                      case QMetaMethod::Slot: typeString = QString("Slot"); break;
                      case QMetaMethod::Constructor: typeString = QString("Constructor"); break;
                      }
                    
                      QString accessString;
                      switch (mm.access()) {
                      case QMetaMethod::Private: typeString = QString("Private"); break;
                      case QMetaMethod::Protected: typeString = QString("Protected"); break;
                      case QMetaMethod::Public: typeString = QString("Public"); break;
                      }
                    
                      qDebug() << accessString << typeString << mm.signature();
                    }
                    

                    @

                    I found one signal for this class. I will try to connect it.[/quote]

                    Better than that:

                    @
                    QString filename="Doc.html";
                    QFile file( filename );
                    if ( file.open(QIODevice::Write) )
                    {
                    QTextStream stream( &file );
                    stream << app->generateDocumentation();
                    }
                    @

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      anagelcg
                      wrote on last edited by
                      #21

                      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?!?!

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Maxbester
                        wrote on last edited by
                        #22

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved