[Qt-interest] Global slot?

Justin Noel justin at ics.com
Fri Mar 6 22:54:25 CET 2009


Israel Brewster wrote:
> I have a slot that I need to be able to connect signals to from  
> multiple places in my application. I know I can make it a function in  
> a header that is included, and then make a slot in each object I need  
> to call the slot from that just calls this function, but I would much  
> prefer to be able to just make a single line connection to a "global  
> slot". To be specific, this slot will be called from menu actions, so  
> it would be really nice to be able to just do addMenu("item  
> whatever",something,globalSlot);
>   

I searched the archive to no avail so I'll just repeat  the answer.
Gregory Seidman did a presentation at ICS's Qt Developer's Meeting in
2003 (pre-cursor to Dev Days) on a Publish/Subscribe system using a
global replay object. He posted a link to the slides on the list at one
point. I can't find them. Here is the jist:

1) Make a singleton QObject with a list of signals you want publishers
to be able to publish like xyz()

2) Connect each object you want to trigger xyz like this:
    connect(action, SIGNAL(activated()),
                   GlobalRelay::instance(), SIGNAL(xyz()));

3) Connect each receiver with:
      connect(GlobalRelay::instance(), SIGNAL(xyz()),
                      this, SLOT(doSomething()));

That setup might a little elaborate for what you want to do. You could
just have the global object implement slots you want executed.

--Justin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: justin.vcf
Type: text/x-vcard
Size: 233 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090306/50ad21fe/attachment.vcf 


More information about the Qt-interest-old mailing list