[Qt-interest] emitting signal from another class

John McClurkin jwm at nei.nih.gov
Fri Jul 16 14:33:27 CEST 2010


Sajjad wrote:
> 
> 
> On Thu, Jul 15, 2010 at 8:12 PM, Scott Aron Bloom 
> <Scott.Bloom at onshorecs.com <mailto:Scott.Bloom at onshorecs.com>> wrote:
> 
> 
> 
>      > -----Original Message-----
>      > From: qt-interest-bounces at trolltech.com
>     <mailto:qt-interest-bounces at trolltech.com> [mailto:qt-interest-
>     <mailto:qt-interest->
>      > bounces at trolltech.com <mailto:bounces at trolltech.com>] On Behalf
>     Of John McClurkin
>      > Sent: Thursday, July 15, 2010 10:58 AM
>      > To: qt-interest at trolltech..com <mailto:qt-interest at trolltech.com>
>      > Subject: Re: [Qt-interest] emitting signal from another class
>      >
>      > Scott Aron Bloom wrote:
>      > >> John:
>      > >>
>      > >>> Ooops. Signals are protected. Only the class that defines the
>      > signal
>      > >>> can emit the signal. What you need is a public member function
>     that
>      > >>> emits the signal.
>      > >> There's an "escape clause", though, isn't there? By connect()ing
>     one
>      > >> signal to another, you can coerce a class to emit its signal in
>      > >> response to another class's compatible signal, right?
>      > >>
>      > >> As long as the connect() has access to the right objects from both
>      > >> classes, you're in business.
>      > >>
>      > >> Atlant
>      > >>
>      > >>
>      > > Yes.. you can absolutely connect one signal to another...
>      > >
>      > > Another method, that I have used (as does the Qt source) is
>     create a
>      > > "emitSignal" method
>      > >
>      > > void MyClass::emitTheSignal( xxx, yyy )
>      > > {
>      > >     emit theSignal( xxx, yyy );
>      > > }
>      > >
>      > However, what the OP seems to be doing is having a class call a
>     method
>      > in a singleton class to modify data in the singleton class. Then,
>     from
>      > within the modifying class, calling emit on the singleton class. It
>      > would be better for the singleton class's data modification method to
>      > emit the signal.
>     Im not sure what the OP's intent was... Since he was trying to call
>     emit obj->signalName()
> 
>     Its not clear to me...
> 
> 
> Hello forum,
> 
> Thanks for the feedback. This is how i solved the issue.
> 
> I have 2 different gl widget class and a singleton shared class . The 
> glwidget class can access and update the data members of the singleton 
> class. When ever the data changes(data of singleton class object) in any 
> of the widgets class i  emit a signal belonging to a gl widgets class. 
> This signal is connected to the signal of the singleton class object. 
>  And the last signal is connected to a slot in the main window..
> 
> 
> Any other better way to accomplish that ?
> 
>

Another possibility: Since the gl widget classes can access and update 
the data members of the singleton class and since the gl widget classes 
emit signals, just connect the signals from the gl widget classes 
directly to the main window. From your description, it does not seem 
necessary for the singleton class to emit any signals.



More information about the Qt-interest-old mailing list