PDA

View Full Version : How accessing a member of a Widget in a QList?



jiveaxe
31st October 2007, 15:26
Hi,
I have created a new widget and called it MyWidget (it includes some qcomboboxes and some qlabels); then I have created a QList like this:


QList<QWidget *> myList;

and appended 2 myWidget:


myWidget_1 = new MyWidget;
myWidget_2 = new MyWidget;
myList.append(myWidget_1);
myList.append(myWidget_2);

Now, how can i access a combobox in one of myWidget? The following code gives error during compilation (error: ‘class QWidget’ has no member named ‘comboBox’):


int index = myList.at(0)->comboBox->currentIndex();


Regards

jpn
31st October 2007, 16:00
As the error message states, QWidget has no such member. You should store MyWidget pointers if you want to access MyWidget members:

QList<MyWidget*> myList;
PS. You should try to avoid public variables ;)

jiveaxe
31st October 2007, 16:11
Thank's jpn,
now works.

Bye