Results 1 to 3 of 3

Thread: Best way to represent struct using Qt containers

  1. #1
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Best way to represent struct using Qt containers

    Hi,

    I want to convert the oneitem struct into one of Qts container classes. Oneitem has three components, so cannot use QPair or QList. I need to have array of oneitems. any ideas?

    Qt Code:
    1. struct itemdetail {
    2. double a;
    3. double b;
    4. } ;
    5.  
    6. struct oneitem
    7. {
    8. struct itemdetail originalitem;
    9. QString desc;
    10. QMap<int, QPair<struct itemdetail, int> > growth;
    11.  
    12. };
    To copy to clipboard, switch view to plain text mode 

    Cheers

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Best way to represent struct using Qt containers

    I need to have array of oneitems.
    So why dont you use QList ?
    Qt Code:
    1. QList<oneitem> list;
    To copy to clipboard, switch view to plain text mode 
    Btw. you can skip the "struct" keyword when declaring the variable:
    Qt Code:
    1. struct itemdetail {
    2. double a;
    3. double b;
    4. } ;
    5.  
    6. struct oneitem
    7. {
    8. itemdetail originalitem; // 'struct' not needed here
    9. QString desc;
    10. QMap<int, QPair<itemdetail, int> > growth; // 'struct' not needed
    11. };
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stampede for this useful post:

    rajil.s (25th January 2012)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Best way to represent struct using Qt containers

    In 99% of the cases any data-based structure can just be mapped to QVariantMap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 5
    Last Post: 10th May 2011, 20:38
  2. What do pointer values actually represent?
    By hackerNovitiate in forum General Programming
    Replies: 2
    Last Post: 26th February 2011, 21:57
  3. Represent a bit vector
    By danilodsp in forum Newbie
    Replies: 3
    Last Post: 20th October 2010, 16:10
  4. represent svg in tab view
    By Dilshad in forum Newbie
    Replies: 5
    Last Post: 27th July 2010, 09:47
  5. how to represent a graph?
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2009, 14:37

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.