Do someone know a solution to do get properties of a QPushButton placed in a QList<QWidget *> ?
.h
QList<QWidget *> list;
.cpp
QPushButton *button = new QPushButton("Push", this);
list->append(button);
qDebug() << list.at(0)->text(); // Not working : text() is not a property of QWidget but a property of QPushButton
Thx
The problem is more to do with
c++and polymorphism in general rather than anything specific toQt. The expression...returns a
QWidget *. Hence the call...fails to compile as
QWidgethas no member function namedtext. If you think the pointer returned bylist.at(0)points to a specific subclass ofQWidgetthen you need to downcast it and check the result before using it. e.g.Alternatively -- since you are using
Qt-- you can make use ofqobject_castin a similar fashion...