[Qt-interest] emitting signal from another class

John McClurkin jwm at nei.nih.gov
Thu Jul 15 19:58:14 CEST 2010


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.



More information about the Qt-interest-old mailing list