Results 1 to 6 of 6

Thread: Slot connected to a generic signal

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Slot connected to a generic signal

    Hello!

    I never heard of this and don't remember that on the manual, but... is there a way to connect a generic signal to a object's slot?

    What I mean is: the normal way of doing signal/slot connection is to take a speific object's signal and connect it to a specific object's slot. But lets suppose I create an object that should have many other objects related to it by means of passing some info. The normal way would be that for each new object created, I would have to once again to a QObject::connect() call between signal and slot. So instead of having to do such an effort, why don't create an specification that tells "all signals with the exact name "xxxx", no matter from which object it comes from, shall be connected to this object's slot"? Something like:

    Qt Code:
    1. connect(0,SIGNAL(mySignal(QString)),myObject,SLOT(slotMySlot(QString)));
    To copy to clipboard, switch view to plain text mode 

    That would be something interesting So is there a way of doing this?

    Thanks,

    Momergil
    May the Lord be with you. Always.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot connected to a generic signal

    The way signal/slot works is that the sender object knows a list of receivers and when the signal is "emitted", the code iterates over this list and calls the receiver slots.

    Without sender there is no such list, so no where to store the connect's information.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Momergil (26th June 2014)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot connected to a generic signal

    Quote Originally Posted by anda_skoa View Post
    Without sender there is no such list, so no where to store the connect's information.
    Well, that is understandable, but still it shouldn't be an actual problem to my "proposal". I mean, the qmake system could simply, once the order is given, create this list inserting the connection for all senders that has that particular signal implemented; it doesn't look like a blocker to me.

    Anyway, thanks for the reply.

    Momergil
    May the Lord be with you. Always.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot connected to a generic signal

    Even if we do not consider objects of classes that are not known at build time, e.g. from plugins, this would still not solve the problem.

    The QObject class declares the list, but without an instance there is no list instance.

    If you need this for a class of your own, you can implement that in that class.
    Implement a static "pre-connect" method that stores lists of signal,receiver,slot triples and each instance works through that list in its constructor.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    Momergil (27th June 2014)

  7. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Slot connected to a generic signal

    Quote Originally Posted by anda_skoa View Post
    If you need this for a class of your own, you can implement that in that class.
    Implement a static "pre-connect" method that stores lists of signal,receiver,slot triples and each instance works through that list in its constructor.
    Very interesting idea (at least if I understood it properly ). Thanks!

    Momergil
    May the Lord be with you. Always.

  8. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Slot connected to a generic signal

    connect(0,SIGNAL(mySignal(QString)),myObject,SLOT( slotMySlot(QString)));
    This reminds me of the famous "COME FROM" statement in FORTRAN.

Similar Threads

  1. Replies: 3
    Last Post: 29th September 2013, 11:46
  2. Replies: 11
    Last Post: 2nd February 2013, 14:39
  3. Replies: 2
    Last Post: 26th August 2011, 08:51
  4. Replies: 2
    Last Post: 18th April 2011, 22:03
  5. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 10:00

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.