qt - How to handle QComboBox signals in inner classes -
i using qt5 , have created class "outer" "inner" class. "inner" class has 2 qcombobox "cb1" , "cb2" objects private variables.
in principle, displayed text of second qcombobox, "cb2", depends of current text of first qcombobox "cb1". in fact, easy implement connection between these two, using signals , slots writing appropriate slot.
the problem qt not support writing slots inside inner class. makes me confused.
how can handle connection between these 2 qcomboboxes in "inner" class?
for code,
class outer : public qdialog { q_object // private variables; class inner : public qwidget { qcombobox *cb1, *cb2; // other variables; public: // public methods public slots: void setindex(int i); }; // other things; };
inner implementation
outer::inner::inner() { // useless things; connect(cb1, signal(currentindexchanged(int)), this, slot(setindex(int))); } outer::inner::setindex(int i) { // stuff retrieve correct index in cb2; }
in qt 5, method can connected signal, whether marked slot or not, describing non problem.
you need use modern connect
syntax, , work fine:
connect(cb1, &qcombobox::currentindexchanged, this, &outer::inner::setindex);
of course, nothing else work correctly: qobject_cast
mechanism won't work, metadata wrong, etc.
an inner class cannot qobject
. fail see point of it. make local class in .cpp
file instead of inner class.
Comments
Post a Comment