problem with a list of pointers
hey, I have done a list of pointers of QWidget. Everything is well done but I want to simplify the last declaration with a for.
My code is the following one:
QList <QWidget*> v;
QVector <int> v_pos(60);
int i_sc =0;
ONE *p1 = new ONE();
v.insert(i_sc,p1);
v_pos[i_sc]= SC_ONE;
i_sc++;
TWO *p1 = new TWO();
v.insert(i_sc,p1);
v_pos[i_sc]= SC_TWO;
i_sc++;
int i;
QList<QWidget*> list;
list.replace(SC_ONE,p1);
list.replace(SC_TWO,p2);
p1->getScreenDirectionlist(&list);
p2->getScreenDirectionlist(&list);
Now, I have changed
"p1->getScreenDirectionlist(&list);" for "v.at(0)->getScreenDirectionlist(&list);"
but It give this error Description Resource Path Location Type
invalid conversion from `QWidget* const' to `ONE*' main.cpp tfp003 83 C/C++ Problem
Do you know ho can i solve it?
thanks
Re: problem with a list of pointers
Re: problem with a list of pointers
how can I use foreach?what does it do?
Re: problem with a list of pointers
Re: problem with a list of pointers
but is i do with a foreach,i have the same problem.
foreach (QWidget *widget, list) {
v.at(0)->getScreenDirectionlist(&list);
}
What I need is to link my pointers of the widget that I have got, with the whole list in a for. this:p1->getScreenDirectionlist(&list); but with a for to make shorter the code.
Re: problem with a list of pointers
No, you have to do this
Code:
foreach
(QWidget *widget, yourWidgetsList
) { widget->getScreenDirectionlist(some_other_list);
}
There is a little bit confusion about v and list. What are they for?
Re: problem with a list of pointers
Quote:
Originally Posted by
maider
Now, I have changed
"p1->getScreenDirectionlist(&list);" for "v.at(0)->getScreenDirectionlist(&list);"
but It give this error Description Resource Path Location Type
invalid conversion from `QWidget* const' to `ONE*' main.cpp tfp003 83 C/C++ Problem
It's a pure C++ problem. The at operator delivers back a pointer to a widget as you have defined your list v! So you have to cast the pointer to your class. Use qobject_cast for that.