Results 1 to 3 of 3

Thread: Storing Data in Models using QVariants or Non-variant Types

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Storing Data in Models using QVariants or Non-variant Types

    I've got a model/view set up and for the most part, it's working pretty well, but I'm uncertain about one of the choices I made. It occured to me that constantly converting to QVariant in the data method for visual updates was probably more expensive than storing the data in QVariant's inside the model and then just returning the data as-is. The downside is that I keep making mistakes external to the model. In a few cases, I've changed the base data type of a column, but then I have to find all of the places where I extract the data and fix up the "toInt", "toString" or whatever.

    I know that Qt does some pretty incredible things to improve performance, and I'm wondering if I'm shooting myself in the foot worrying about the QVariant conversion. My code would be more reliable using non-variant types in the model because my property methods would change types and the compiler would flag most everything that needs to be fixed up.

    Thoughts?

    Thanks,
    Doug

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Storing Data in Models using QVariants or Non-variant Types

    I think I would store non-variant types in the model and not worry about the conversions. The views used by Qt are pretty smart - they will usually only ask for data that is actually displayed, and there is only so much you can show at one time.

    Where you are likely to take a hit is in proxy models where you must sort the model before you can display it. If you have to repeatedly convert from a QVariant into some native type in order to do sort order comparisons, this could be very expensive.

  3. #3
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing Data in Models using QVariants or Non-variant Types

    Thanks -- I hadn't thought about the sorting aspect yet, and I do need that (probably starting on that today). I'd been leaning towards using the native types anyway, and this confirms my gut feeling. Appreciate the help!

    Doug

Similar Threads

  1. Replies: 0
    Last Post: 4th October 2011, 07:52
  2. Saving and storing data,QtSql
    By salmanmanekia in forum Newbie
    Replies: 7
    Last Post: 20th April 2010, 20:08
  3. Qt types exposed as Variant in javascript
    By dioselin in forum Newbie
    Replies: 1
    Last Post: 15th April 2010, 18:08
  4. Storing and reading back template types in QVariant
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2010, 08:40
  5. storing data in hexadecimal format
    By aj2903 in forum Qt Programming
    Replies: 6
    Last Post: 13th January 2010, 06:29

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.