C++ QWidget class has no member (n)
-
Good day!
I'm having the following problem:
I have a custom class named WidgetStyle, inheriting from a QWidget.
WidgetStyle has a std::string variable called MY_Style, which stores custom informationI add a lot of these items to a layout and have to iterate through them and get the variable MY_Style stored in them.
for (int i = 0; i < MyLayout->count(); i++) { MyLayout->itemAt(i)->widget()->MY_Style }
C++ returns the error : "class QWidget has no member MY_Style"
, which if they were normal qwidgets they wouldn't have that member, but how do I indicate to c++/QT that the items in the layout are not QWidgets but instead my inherited WidgetStyles that do have that property/member?
Thank you!
-
Good day!
I'm having the following problem:
I have a custom class named WidgetStyle, inheriting from a QWidget.
WidgetStyle has a std::string variable called MY_Style, which stores custom informationI add a lot of these items to a layout and have to iterate through them and get the variable MY_Style stored in them.
for (int i = 0; i < MyLayout->count(); i++) { MyLayout->itemAt(i)->widget()->MY_Style }
C++ returns the error : "class QWidget has no member MY_Style"
, which if they were normal qwidgets they wouldn't have that member, but how do I indicate to c++/QT that the items in the layout are not QWidgets but instead my inherited WidgetStyles that do have that property/member?
Thank you!
@Pekoyo
As @Kent-Dorfman says. To that end have a look at qobject_cast<>(). -
you need to research and learn c++ casts...and related, the use of virtuals.
widget() is probly returning a qwidget* as its type, so it wont' understand an implicit cast to the subclass.
-
Good day!
I'm having the following problem:
I have a custom class named WidgetStyle, inheriting from a QWidget.
WidgetStyle has a std::string variable called MY_Style, which stores custom informationI add a lot of these items to a layout and have to iterate through them and get the variable MY_Style stored in them.
for (int i = 0; i < MyLayout->count(); i++) { MyLayout->itemAt(i)->widget()->MY_Style }
C++ returns the error : "class QWidget has no member MY_Style"
, which if they were normal qwidgets they wouldn't have that member, but how do I indicate to c++/QT that the items in the layout are not QWidgets but instead my inherited WidgetStyles that do have that property/member?
Thank you!
@Pekoyo
As @Kent-Dorfman says. To that end have a look at qobject_cast<>(). -
-
Good day!
I'm having the following problem:
I have a custom class named WidgetStyle, inheriting from a QWidget.
WidgetStyle has a std::string variable called MY_Style, which stores custom informationI add a lot of these items to a layout and have to iterate through them and get the variable MY_Style stored in them.
for (int i = 0; i < MyLayout->count(); i++) { MyLayout->itemAt(i)->widget()->MY_Style }
C++ returns the error : "class QWidget has no member MY_Style"
, which if they were normal qwidgets they wouldn't have that member, but how do I indicate to c++/QT that the items in the layout are not QWidgets but instead my inherited WidgetStyles that do have that property/member?
Thank you!