Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    4
    12
    2508
    Loading More Posts
    • 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
      aabc last edited by

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

      1 Reply Last reply Reply Quote 0
      • M
        mbnoimi last edited by

        I'm not sure what do you mean but QVariant works fine with maximum value of int

        @#include <QCoreApplication>
        #include <QDebug>
        #include <limits>

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

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

        }
        @

        You can past a snippet in case that's not what you mean.

        1 Reply Last reply Reply Quote 0
        • A
          aabc last edited by

          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 Reply Quote 0
          • raven-worx
            raven-worx Moderators last edited by

            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 Reply Quote 0
            • M
              mbnoimi last edited by

              [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 Reply Quote 0
              • A
                aabc last edited by

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

                1 Reply Last reply Reply Quote 0
                • raven-worx
                  raven-worx Moderators last edited by

                  [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 Reply Quote 0
                  • A
                    aabc last edited by

                    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 Reply Quote 0
                    • A
                      amccarthy last edited by

                      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 Reply Quote 0
                      • raven-worx
                        raven-worx Moderators last edited by

                        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 Reply Quote 0
                        • A
                          aabc last edited by

                          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 Reply Quote 0
                          • A
                            aabc last edited by

                            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 Reply Quote 0
                            • First post
                              Last post