How to "signal" from a non-QObject?
-
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?
-
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?
-
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?
-
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.
-
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. -
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
-
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