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. Does anyone know why big int values on QVariant store as double ?
Forum Updated to NodeBB v4.3 + New Features

Does anyone know why big int values on QVariant store as double ?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 3.1k 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #3

    Try to use it this way:

    @
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    int x = INT_MAX;
    QVariant v1 = x;
    qDebug() << v1;
    
    return a.exec&#40;&#41;;
    

    }

    @

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #4

      this outputs the following in the console for me:
      [quote]QVariant(int, 2147483647)[/quote]

      Which compiler are you using?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #5

        [quote author="aabc" date="1367143234"]Try to use it this way:[/quote]

        It works fine to me!!! I got this:

        bq. QVariant(int, 2147483647)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aabc
          wrote on last edited by
          #6

          It happens when I use it with QML (Created C++ QML object)

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #7

            [quote author="aabc" date="1367143234"]Try to use it this way:

            @
            int main(int argc, char *argv[])
            {
            QCoreApplication a(argc, argv);

            int x = INT_MAX;
            QVariant v1 = x;
            qDebug() << v1;
            
            return a.exec&#40;&#41;;
            

            }
            @
            [/quote]

            well..whats your output of these lines?!

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aabc
              wrote on last edited by
              #8

              The same as yours.
              This problem happens when I use it with QML.
              For some reason if I pass large int to variant property (C++ QVariant) it stores it as double

              1 Reply Last reply
              0
              • A Offline
                A Offline
                amccarthy
                wrote on last edited by
                #9

                QML/JavaScript only has a single number type, implemented as a double. Assigning directly to a QVariant property will keep this type information. Is this what you are seeing?

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #10

                  show the code please.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    aabc
                    wrote on last edited by
                    #11

                    Not exactly.
                    Whan I assign to QML int property small value (such as 500) the C++ QVariant stores it as int.
                    But when I assign to this QML int property large value (such as 1111111111) the C++ QVariant stores it as double.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      aabc
                      wrote on last edited by
                      #12

                      C++:

                      @
                      class MyItem: public QObject
                      {
                      Q_OBJECT

                      Q_PROPERTY(QVariant value       READ value          WRITE setValue  NOTIFY valueChanged)
                      

                      public:
                      inline const QVariant& value() const
                      {
                      return m_value;
                      }

                      inline void setValue(const QVariant& _value)
                      {
                          qDebug() << "_value = " << _value;
                          qDebug() << "m_value = " << m_value;
                      
                          if(_value != m_value)
                          {
                              m_value = _value;
                              emit valueChanged();
                          }
                      }
                      

                      private:
                      QVariant m_value;
                      }
                      @

                      QML:

                      @
                      property int myQmlInt: 111111111

                      MyItem
                      {
                      id: myItem1
                      value: myQmlInt
                      }
                      @

                      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