Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVariant for int/double members that could be "Null" ?
Forum Updated to NodeBB v4.3 + New Features

QVariant for int/double members that could be "Null" ?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jeremy_c
    wrote on last edited by
    #1

    Hello,

    I am porting a few methods/classes from C/++ and some have int/double members that could be "Null." I assigned them a known invalid value in the old code to indicate they are "Null."

    I am wondering if in Qt if it would be a better practice to use a QVariant in these cases? Is there any "best practice" for handling these types of properties? The data will be read from a database, edited by the user in a GUI form, displayed on reports and various file exports.

    Thanks for any suggestions,

    Jeremy

    Jeremy
    http://www.kb8lfa.com

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Common pratice for i is to use known invalid values as you did, but as from my POV it is slightly ugly and error-possible. Also there are sometimes custom classes-wrappers, but it removes POD attribute from variable. Qvariant is a standartized and common for big number of types solution and handles a lot of non-usual states.

      QVariant is a good solution for you I think.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jeremy_c
        wrote on last edited by
        #3

        Thanks Denis. I gave it some more thought and decided to go the QVariant way.

        Jeremy
        http://www.kb8lfa.com

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved