PDA

View Full Version : QList question



MarkoSan
23rd January 2008, 05:24
Good morning!

I have declaration:
QPointer<QList<QPointer<CFlagButton> > > m_pLangButtonGroup; // pointer to list of pointers to CFlagButtonHow do I create new and empty m_pLangButtonGroup? CFlagButton is subclass of QPushButton.

Code:
m_pLangButtonGroup=new QList(); fails. Why?

jpn
23rd January 2008, 07:15
Good morning!
Morning :)



I have declaration:
QPointer<QList<QPointer<CFlagButton> > > m_pLangButtonGroup; // pointer to list of pointers to CFlagButton
QList is an implicitly shared class (http://doc.trolltech.com/4.3/shared.html). It gives no real benefits to allocate it on the heap, it only makes things unnecessarily more complex. Furthermore, QPointer works on QObjects, whereas QList is not a QObject.



Code:
m_pLangButtonGroup=new QList(); fails. Why?
Because QList is a template class, you cannot instantiate QList(). It should be QList<Type>(). But as I said, QList is not a QObject so this change alone won't make it compile.

MarkoSan
23rd January 2008, 07:51
Ok, thanks!

Will allocate needed class on stack .... and then again beg for help I think. :D