Results 1 to 7 of 7

Thread: QList problem

  1. #1
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Smile QList problem

    Hello,

    I want to make a QList like this

    Qt Code:
    1. makeSphere
    2. center
    3. radius
    4.  
    5. makeBox
    6. width
    7. length
    8. height
    To copy to clipboard, switch view to plain text mode 

    How can I do this?

    Thank you!

  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: QList problem

    Use QTreeWidget / QTreeView

  3. #3
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QList problem

    Hi,

    I am processing a large amount of data.
    Is QTreeWidget / QTreeView the best solution for this?

    Thanks

  4. #4
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QList problem

    What do you mean with "make a QList like this"?

    Do you want to display data like this? Then use a QTreeView.
    What is the data source (a QList has no parents/childs)?

  5. #5
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QList problem

    Hi Infinity,

    I don't want to display.
    I want to store data in something like a QList that has a parent(QString) and children(QString)

    Thanks

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QList problem

    You can construct your own data structure however you want using the facilities offered by C++ and Qt. How you do it depends on exactly what the requirement is and how you have to manipulate the data.

    One possibility for the problem as posted is:
    Qt Code:
    1. struct Entry {
    2. Entry(const QString &n, const QStringList &c = QStringList()):
    3. name(n), children(c)
    4. { }
    5. QString name;
    6. QStringList children;
    7. };
    8. QList<Entry> mySingleLevelHeirarchy;
    To copy to clipboard, switch view to plain text mode 

    If the structure needs to be arbitrarily deep
    Qt Code:
    1. struct Entry {
    2. Entry(const QString &n, const QList<Entry> &c = QList<Entry>()):
    3. name(n), children(c)
    4. { }
    5. QString name;
    6. QList<Entry> children;
    7. };
    8. QList<Entry> myMultiLevelHeirarchy;
    To copy to clipboard, switch view to plain text mode 

    You could even use QStandardItemModel if you really wanted to.

  7. #7
    Join Date
    May 2013
    Posts
    45
    Thanks
    6
    Thanked 6 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QList problem

    Thank you, problem solved

Similar Threads

  1. Problem with QList
    By just-in in forum Qt Programming
    Replies: 9
    Last Post: 22nd August 2013, 18:12
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. QList problem
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 19th January 2010, 05:40
  4. Problem with QList
    By Gargolissimus in forum Newbie
    Replies: 8
    Last Post: 6th July 2009, 16:24
  5. QList problem
    By acix in forum General Programming
    Replies: 6
    Last Post: 29th April 2006, 13:08

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.