[Qt-interest] Compile error for QList<T> containing pointer to objects of my own class
Duane Hebert
spoo at flarn.com
Mon Jan 4 20:46:13 CET 2010
"Pedro Santos" <nonspam2048 at yahoo.de> wrote in message news:hhtfm9$6nu$1 at eple.troll.no...
> Hello,
> I try to store pointer to objects of my own class "Script" into a QList<T>. In
> mainwindow.h I wrote:
>
> private:
> QList<Script*> _listAllScripts;
>
> then I tried to instatiate it in the constructor of mainwindow.cpp:
>
> _listAllScripts = new QList<Script*>();
>
> Unfortunately I get the following compiler error :(, so what is wrong:
>
> mainwindow.cpp:36: error: no match for ‘operator=’ in
> ‘((MainWindow*)this)->MainWindow::_listAllScripts = (operator new(8u),
> (<statement>, ((QList<Script*>*)<anonymous>)))’
_listAllScripts is a Qlist<Script*>, not a pointer so you can't assign it to something
created by new(). The error message is telling you that.
Create your list of Script* and use push_back() or insert() or << to fill it like
QList<Script*> listAllScripts;
listAllScripts.push_back(new Script());
BTW, you should not use leading _ in your variable names as _ and __ are reserved.
More information about the Qt-interest-old
mailing list