Results 1 to 3 of 3

Thread: QList question

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QList question

    Good morning!

    I have declaration:
    Qt Code:
    1. QPointer<QList<QPointer<CFlagButton> > > m_pLangButtonGroup; // pointer to list of pointers to CFlagButton
    To copy to clipboard, switch view to plain text mode 
    How do I create new and empty m_pLangButtonGroup? CFlagButton is subclass of QPushButton.

    Code:
    Qt Code:
    1. m_pLangButtonGroup=new QList();
    To copy to clipboard, switch view to plain text mode 
    fails. Why?
    Qt 5.3 Opensource & Creator 3.1.2

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QList question

    Quote Originally Posted by MarkoSan View Post
    Good morning!
    Morning

    I have declaration:
    Qt Code:
    1. QPointer<QList<QPointer<CFlagButton> > > m_pLangButtonGroup; // pointer to list of pointers to CFlagButton
    To copy to clipboard, switch view to plain text mode 
    QList is an implicitly shared class. 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:
    Qt Code:
    1. m_pLangButtonGroup=new QList();
    To copy to clipboard, switch view to plain text mode 
    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.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QList question

    Ok, thanks!

    Will allocate needed class on stack .... and then again beg for help I think.
    Qt 5.3 Opensource & Creator 3.1.2

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 19:55
  2. Interface methods question
    By sincnarf in forum Qt Programming
    Replies: 3
    Last Post: 5th October 2007, 11:20
  3. Q3Ptrlist v/s QList
    By joseph in forum Qt Programming
    Replies: 3
    Last Post: 25th September 2007, 12:27
  4. QList question
    By aamer4yu in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2007, 14:43
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 21:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.