signal slot to mainwindow
hello.
I'm read about the behaviour of signal/slot in qt.
My problem is that i have created a custom widget and the emission of the signal(emit pressed()) is in a custom delegate of my project.
How i can "take out" the signal for invoke the "pressedButton()" slot that is in the main window?
i must send the main window pointer(m_pMainWindow) and transport it to the delegate?
where i can do:
Code:
connect(this, SIGNAL(pressed()),
m_pMainWindow, SLOT(prssedButton())));
is correct?
thanks.
Re: signal slot to mainwindow
that is bad design. Normally you should do it the other way around:
Code:
connect(my_custom_widget, SIGNAL(pressed()),
this, SLOT(pressedButton())));
This is so that clients of the signal do not have to be known to the emitter. This maintains dependency injection principles.
Re: signal slot to mainwindow
thanks, another thing :
I have this code in the main function , but the "connect" function works only if the class inherits from QOBject(is correct?) and the main function is not a class function.
then I have a openglwidget that inherits from qobject and the opengl code that don't inherits from qobject how i can manage all the signals and slots?
I must create a central class(that inherits from QObject) that works as a bridge from qt to opengl and other possible subsystems?
thanks.
Re: signal slot to mainwindow
you can just use
QObject::connect(qobjectPtr1, SIGNAL(some_signal()), qobjectPtr2, SLOT(some_slot()));