Issues connecting signal and slots[SOLVED]
-
Hi,
checkInput is called in patientinfo's constructor which means the signal is emitted before the connection happens.
-
@SGaist
Ah, good spotted. -
@SGaist I can't think of another way to write the code. Can you give me suggestions?
-
Ok so I created the connection in patientinfo.cpp and commented out the one in mainwindow.cpp
_idNameBar = new IdNameBar; . . . connect(this,SIGNAL(checkInputSignal()),_idNameBar,SLOT(onCheckInput())); checkInput(); }
and on patientinfo.h I added
#include "idnamebar.h" IdNameBar *_idNameBar;
I get the qdebug output as :
checking mySig
checking slot
emitting slot
emitted mySigthe button does not disable though
-
Now it's another subtlety: the event loop has not yet started, so it's not yet propagating.
Anyway, the current architecture doesn't look quite right. onCheckInput just disables the next button, how do you plan to enable it again ?
What you describes sounds a bit like QWizard, you should take a look at that class.
-
@SGaist I really do not want to use QWizard since I don't want that exact look. I know I have to enable it again but I am doing it step by step. I just want to make the button disabled if that field is empty. Once I can make that work, I will work on enabling it again once there is something in that field which is the patient name.
-
Then you should rather add a signal to your patientinfo class that contains a boolean parameter to tell whether the its content is empty or not and connect that signal to your IdNameBar class. patientinfo should not have to care nor know about IdNameBar, it's not its responsibility.
-
@SGaist I have tried doing that but nothing happens still. The qdebug tells me i did go to the slot but the button is still enabled no matter what.
-
Since you don't want to disable the button at construction time (which would be logical since no validation has been done), then you must trigger the check after the event loop has started. You can use a single shot QTimer with a timeout at 0 for that.
-
Ohh so you mean to disable the button at the beginning no matter what? I guess that makes sense. Ill try that!
-
I just want to remind you that many errors can be caught if you use the new Qt Connect syntax.
-
I followed this post: https://forum.qt.io/topic/4847/how-to-enable-a-submit-button-after-multiple-form-fields-have-been-verified/13
and now it works! Thank you