c++ - Qt Slots and Signals. Get Slot Receiver Object -


i have qlineedit want connect qlabel depending on validity of text entered. have 2 problems while doing this.

qlineedit *text = new qlineedit(this); layout->addwidget(text, rowno, 0); qlabel *button = new qlabel(this); button->setstylesheet("qlabel { background-color : green; color : white; }"); button->setalignment(qt::aligncenter); button->settext("okay"); qobject::connect(text, signal(textedited(const qstring &)), button, slot(checkvalidity(const qstring &))); 

this not connect changes made in qlineedit custom slot. cannot figure out why! in custom slot, want change background colour of label depending on qstring passed. how reference label? present receiver of signal can't figure out way refer it.

checkvalidity not qbutton's slot, it's custom slot defined in own class (i assume that, since have not specified it).

so, change last line to:

qobject::connect(text, signal(textedited(const qstring &)), this, slot(checkvalidity(const qstring &))); 

if want know sender object, use qobject_cast:

qlabel *sender_label = qobject_cast<qlabel*> (sender ()); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -