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()));
ui->webBox->layout()->addWidget(JanusKeyholderMenuUi);@Testing the connect returns "true", so the connect should work anyway.
Used to trigger:
@emit paintJanusStaff();@Declaration:
@signals:
void paintJanusStaff();@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:
@void JanusKeyholderMenu::parsePerson()
{
iKeyholderIDList.clear();
iOrgUnitIDList.clear();
strLastNameList.clear();
strFirstNameList.clear();
strInitialsList.clear();
strTitleList.clear();
arrKeyCodesList.clear();
dtStartDateTimeList.clear();
dtEndDateTimeList.clear();
strEmployeeNumberList.clear();
strEmailList.clear();
dtDateOfBirthList.clear();
strWorkTelephoneList.clear();
strHomeTelephoneList.clear();
strMobileTelephoneList.clear();
iKeyholderCategoryIDList.clear();
aAccessGroupsList.clear();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:
mainwindow.cpp
@ qDebug() << "openeing janus";
JanusKeyholderMenu *JanusKeyholderMenuUi = new JanusKeyholderMenu(screenX, screenY, lang, buttonTextSize);
qDebug() << "connect:" << connect(JanusKeyholderMenuUi, SIGNAL(paintJanusStaff()), this, SLOT(paintJanusStaff()));
qDebug() << "connected!";@januskeyholder.cpp
@ qDebug() << "right before emit";
emit paintJanusStaff();
qDebug() << "right after emit";@output:
@openeing janus
right before emit
right after emit
sending list...
connect: true
connected!@ -
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.