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) 

(https://github.com/qt/qtbase/blob/e4c39d5e1e7ee8c2bba273e6d613ec519b7fa9c2/src/corelib/kernel/qobject.cpp#l2659)

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

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -