Results 1 to 3 of 3

Thread: how to initialize an empty QList in the initialization list?

  1. #1
    Join Date
    Sep 2008
    Posts
    23
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question how to initialize an empty QList in the initialization list?

    hi, there
    suppose I define
    Qt Code:
    1. QList<MyStuff* > list;
    To copy to clipboard, switch view to plain text mode 
    in the header file. And I need to initialize an empty list in the initialization list of MyClass. How can I do that?
    Qt Code:
    1. MyClass::MyClass() : list(0) {...} // won't compile
    2. MyClass::MyClass() : list() {...} // not initialized
    3. MyClass::MyClass() : list() {QList()} // not initialized
    4. //what's the correct way to do that? It's fine if I have to use QList<MyStuff* > * list.
    To copy to clipboard, switch view to plain text mode 
    Thanks for help. I'm waiting online.
    zl

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to initialize an empty QList in the initialization list?

    Try this
    MyClass::MyClass() : list(QList<MyStuff*> ())

  3. The following 2 users say thank you to aamer4yu for this useful post:

    Er.Dhananjay (6th May 2014), MarkoSan (20th August 2014)

  4. #3
    Join Date
    Sep 2008
    Posts
    23
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to initialize an empty QList in the initialization list?

    Y, you are correct, thanks very much.
    zl
    Last edited by zl2k; 19th September 2008 at 05:47.

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.