Signal not emitting from some functions
I have a signal/slot system and some signals simply do not work from within specific functions. The reason is quite unclear for me. I'm using Qt 5.4.1.
Init of a new widget + connect method
@ JanusKeyholderMenu *JanusKeyholderMenuUi = new JanusKeyholderMenu(screenX, screenY, lang, buttonTextSize);
connect(JanusKeyholderMenuUi, SIGNAL(paintJanusStaff()), this, SLOT(paintJanusStaff()));
Testing the connect returns "true", so the connect should work anyway.
Used to trigger:
The function from which it works is a simple QPushButton private slot and test function. The other one is a private function which starts like:
qDebug() << "parsing persons..."; emit paintJanusStaff();@
Any help is appreciated!
Can you guarantee that signal is emitted after the connect is made ? This is the only suspect I have now.
tested it and it seems you are right. the signals is emitted before the connection is even established. any idea how to setup the connection before even creating the object?
Here is the test output:
@ qDebug() << "openeing janus";
JanusKeyholderMenu *JanusKeyholderMenuUi = new JanusKeyholderMenu(screenX, screenY, lang, buttonTextSize);
qDebug() << "connect:" << connect(JanusKeyholderMenuUi, SIGNAL(paintJanusStaff()), this, SLOT(paintJanusStaff()));
qDebug() << "connected!";@
@ qDebug() << "right before emit";
qDebug() << "right after emit";@
right before emit
right after emit
This itself indicates that you are emitting the signal from before connecting the signal and slot.
Line#2 is creating the object and you are emiting the signal inside the constructor. Here itself you are emitting the signal.
Line#3 you are connecting the object. By this time signal is already emitted.
In the current logic you can't do like this. You can't emit the signal while creating the object itself and yet catch this same signal by doing the connect. This is logic issue.