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. How to "signal" from a non-QObject?
Forum Updated to NodeBB v4.3 + New Features

How to "signal" from a non-QObject?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 9.1k 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.
  • A Offline
    A Offline
    artem.marchenko
    wrote on last edited by
    #1

    Hi All

    I am creating an app that works with the external non-Qt library (SkypeKit if you wonder). Objects in the library sometimes have events and clients are supposed to inherit library objects and override the virtual methods for noticing an event. I can't figure a good way for propagating the event further into the Qt signals and slots world.

    Here's what architecture looks like:
    @
    Skype // Library object
    |
    SkypeWrapper : public Skype // my wrapper that implements virtual void eventHappened()
    |
    QSkype : public QObject // contains SkypeWrapper as one of its fields
    // QSkype needs to somehow get notification of eventHappened() to propagate it further
    @

    I tried multiple inheritance for SkypeWrapper (from QObject and Skype), but then compiler thows error on moc files: error: 'QObject' is an ambiguous base of 'SkypeWrapper'

    What is the proper way for taking non-Qt events into the Qt world?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      Maybe I'm getting it wrong, but if QSkype has a field of type SkipeWrapper I'd do the following:

      • create a signal in QSkype that corresponds to the Qt translate event you need to propagate
      • create a wrapper method in QSkype that performs the emit of the above signal
      • in the eventHappened method call the above method to translate the event into a Qt signal

      Could it work?

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        What classes does your SkypeWrapper inherit from?

        The error message ‘QObject’ is an ambiguous base of ‘SkypeWrapper’ would make me think that class Skype inherits from QObject already?

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • A Offline
          A Offline
          artem.marchenko
          wrote on last edited by
          #4

          fluca, what I did resembles your idea quite closely. When constructing SkypeWrapper I pass QSkype to as a parent (stored in m_parent) it and then when event happens:
          @
          void SkypeWrapper::onEventHappened() {
          m_parent.engineEventHappaned();
          }
          @

          Then QSkype can do some own handling or emit a Qt world signal.

          It works well, but I am not very happy with two wrapping layers and hoped for some clever trick from people in the similar situations. I guess I am not the only one trying to bring an external library into Qt world.

          Volker, I double-checked just now, Skype doesn't inherit from QObject and actually whole Skype library to my understanding doesn't depend or use anything Qt.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            I think there is not a much more different solution to translate events from an external library into Qt signals. After all you have to translate from one world to the other, so a wrapper is required.
            By the way, the Skype GUI is based on Qt, I would guess that even the "internal" library was Qt based too but I could be wrong.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              foxyz
              wrote on last edited by
              #6

              Hi,Im not sure if next is you want:
              you mean an event occured in Skype than you wanto dispatch this event to another object to process(with slot function)?

              @
              class MyEventDispatcher: public QObject {

              void dispatch( Myevent *e, QObject* receiver); 
              

              };

              class MySkype : public Skype {
              MyEventDispatcher *dispatcher;

              void   event(Myevent* e) { dispatcher->dispatch( e, targetObj); }
              

              }
              @

              Edit: please use @ tags around code sections; Andre

              I just know coding and coding

              1 Reply Last reply
              0
              • A Offline
                A Offline
                artem.marchenko
                wrote on last edited by
                #7

                Yes, foxyz, that's what I want to do. Oh, well, Ideally I'd want SkypeWrapper (or MySkype in your example) just be QObject so that they could both do some processing and propagate signals further if needed.

                Your example is interesting: you put the whole layer of QSkype, QConversation, QParticipant, etc into a single MyEventDispatcher.

                Thanks for the idea, I'll think whether it is more elegant for my case. Tradeoffs will mostly have to be considered on whether I really want the dispatcher (QSkype, QConversation, etc) be just a dispatcher (with app logic somewhere else) or I if want QSkype, QCOnversation, etc actually contain a decent amount of logic

                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