Results 1 to 14 of 14

Thread: QList of variable data type?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    70
    Thanks
    43
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QList of variable data type?

    In my program I import a set of millions of 3D points with multiple properties each (RGB values, XYZ values, alpha, etc) from an external file and store it in memory. Rather than storing them as a simple array, I was hoping to store them in a Qt container class like QList so that I could tap into Qt's sorting capabilites. In order to conserve memory, I've written several class-based point data types to choose from—some with XYZ only, others that store XYZ and RGB data, etc—all that inherit from a core data type:
    Qt Code:
    1. class p3d_core_t {/*variables here*/}
    2. class p3d_0_t : public p3d_core_t {/*variables here*/}
    3. class p3d_1_t : public p3d_core_t {/*variables here*/}
    4. class p3d_2_t : public p3d_core_t {/*variables here*/}
    To copy to clipboard, switch view to plain text mode 
    A given data file specifies in its header which data type it contains (0, 1, 2, ..., N), so I don't know which type to store in my QList until run-time. I have two questions:
    1. How do I construct a new QList during run-time once I know which data type I'm importing?
    2. Is it possible to list the data types themselves in a QHash so that I can index them instead of having a series of if-else statements? For example, something like this
      Qt Code:
      1. int dataTypeIndex = 2;
      2. QList* list;
      3. QHash<int, pointdatatype> hash;
      4. list = new QList<hash.value(dataTypeIndex)>
      To copy to clipboard, switch view to plain text mode 
      would create a QList of p3d_2_t data, ready for importing.

    I can hardcode this with a huge set of if-else statements, but I have a feeling there's an elegant "Qt way" to do this, especially since the number of point data types changes periodically. I'd rather it be a little more flexible. Because these data sets get huge, even a little memory or speed boost makes a huge difference.

    Thanks in advance!

    [edit]
    I'd also like to add that I'm open to alternatives to QList or QHash that are more appropriate for lists that get into the 10-999 million member range.
    [/edit]
    Last edited by Phlucious; 16th November 2011 at 01:00.

Similar Threads

  1. Changing the type of QList
    By wagmare in forum Newbie
    Replies: 4
    Last Post: 19th October 2011, 11:59
  2. Replies: 4
    Last Post: 8th December 2010, 13:22
  3. Replies: 2
    Last Post: 6th October 2010, 22:09
  4. 'QList' does not name a type
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 22nd September 2009, 14:28
  5. Getting Type of an variable
    By hgedek in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2007, 15: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
  •  
Qt is a trademark of The Qt Company.