c++ - QComboBox signal not trigged -
i have checked code several times , still can't why not working. use qcombobox connected slot in class :
this->choixcam = new qcombobox; this->choixcam->additem("camera 1"); this->choixcam->additem("camera 2"); this->choixcam->additem("camera 3"); this->choixcam->additem("all cameras"); qobject::connect(this->choixcam, signal(currentindexchanged(int)), this, slot(this->selectcam(int))); this previous part of code defined constructor of class mainwindows, called in main. definition in header file following :
public: qcombobox* choixcam; public slots: void selectcam(int choixcam); i tried run slot signal.
using signal qstring, signal activated(int) or trying exemple find on net didn't work neither. signals/slots mecanism work qbutton , qspinbox.
i running out of idea. appreciate. thank you.
@eyllanesc answer should work. change slot(this->selectcam(int)) slot(selectcam(int)).
but why isnt same qt? lets have @ connect method:
qmetaobject::connection qobject::connect(const qobject *sender, const char *signal,const qobject *receiver, const char *method, qt::connectiontype type) and @ signal , slot definition:
#define slot(a) "1"#a #define signal(a) "2"#a qt uses c-strings identify signals , slots qobjects. these strings used keywords in kind of dictionary on qobjects, signals , slots. try std::cout << signal(some text) << std::endl; see signal , slot do.
thats why can call connect without signal , slot:
connect(this->choixcam, "2currentindexchanged(int)", this, "1selectcam(int)"); now know slot(this->selectcam(int)) produce "1this->selectcam(int)" keyword instead of "1selectcam(int)"
the signal , slot definitions used because ides disable c++ autocompletion inside quotation marks, makes hard write correct function signature.
Comments
Post a Comment