Results 1 to 4 of 4

Thread: Signals and Slots over interface

  1. #1

    Default Signals and Slots over interface

    All-

    I've got a collection of plugin classes that all implement a proper interface (ie, it the class does not inheirit from QObject) that I'd like to get signals working over. To illustrate (hoping this works and clarifies the issue):

    Qt Code:
    1. CommonClass InterfaceClass
    2. | (inherits) |
    3. | | (implements)
    4. |+Plugin1+-------|
    5. |+Plugin2+-------|
    6. |+Plugin3+-------|
    To copy to clipboard, switch view to plain text mode 

    ** CommonClass (compiled into library) extends QObject, and has declarations for signals and slots
    ** Each Plugin class (compiled into library) extends CommonClass in a "is-a" pattern
    ** InterfaceClass is an interface with *no* implementation and is not a QObject subclass
    ** MainApplication loads PluginN classes via QPluginLoader by qobject_cast-ing to InterfaceClass

    Since InterfaceClass doesn't extend QObject, I can't put signal/slot declarations there; they all extend CommonClass, but it'd be a real pain to qobject_cast the plugins to CommonClass to connect the signals.

    I've looked at how the QObject::connect works and see that it eventually uses the QMetaObejcts from the caller and receiver classes. I can use QMetaObject->superClass() to get the classname of a particular plugin (CommonClass, in this example), but don't seem to be able to get a handle on the signal emitted from CommonClass (and, seemingly therefore each plugin).

    Thoughts or ideas on how to get this working?

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signals and Slots over interface

    Quote Originally Posted by SnarlCat View Post
    ** MainApplication loads PluginN classes via QPluginLoader by qobject_cast-ing to InterfaceClass

    Since InterfaceClass doesn't extend QObject, I can't put signal/slot declarations there; they all extend CommonClass, but it'd be a real pain to qobject_cast the plugins to CommonClass to connect the signals.
    Did it came to you that maybe you could just use the QObject* returned by QPluginLoader?
    Connecting signals/slots does not require that you know anything about the nature of the objects involved. As long as they are QObjects the code will compile and as long as they provide the signals you want (wherever it might be in the object hierarchy) the connection will work as expected.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3

    Default Re: Signals and Slots over interface

    Yes, I tried that.. the QObject::connect(...) failed because it couldn't find the signal in the plugin class as it's declared in CommonClass...

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signals and Slots over interface

    Quote Originally Posted by SnarlCat View Post
    Yes, I tried that.. the QObject::connect(...) failed because it couldn't find the signal in the plugin class as it's declared in CommonClass...
    Sorry but that doesn't make any sense... When you connect signals/slots the meta object system is queryed in a way that exposes ALL the signals/slots of the object, wherever they may be declared in the inheritance hierarchy.
    The only possible issues I can think of are :

    • you screwed up signal/slot declaration at some point
    • you are actually having DLL-related issues

    At this point showing us some code (preferably a small compilable sample reproducing the issue) would help.
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 09:06
  2. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 10:31
  3. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 01:45
  4. signals and slots in plugins
    By anderl in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 13:57
  5. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 00:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.