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. How to convert const QVector<quint32> to vector<int>.
Forum Updated to NodeBB v4.3 + New Features

How to convert const QVector<quint32> to vector<int>.

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 9 Posters 1.9k Views 3 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #3

    Apart from the ususal disclaimer about converting unsigned to siged, you can use

    std::vector<int> l_sensorAddressList(
        reinterpret_cast<const int*>(p_sensorAddressList.constData())
        , reinterpret_cast<const int*>(p_sensorAddressList.constData()+p_sensorAddressList.size())
    );
    

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      While we're at it:

      std::copy(in.begin(), in.end(), std::back_inserter(out));
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      fcarneyF 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        One even simpler version:

        std::vector<int> l_sensorAddressList(std::begin(p_sensorAddressList), std::end(p_sensorAddressList));
        

        or

        std::vector<int> l_sensorAddressList(p_sensorAddressList.begin(), p_sensorAddressList.end());
        

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #6

          Just to clarify: @JohanSolo , @Christian-Ehrlicher and @SGaist 's solutions are correct. My solution should be faster as it's a simple memcpy but the other's might be safer (I don't really see how though)

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            While we're at it:

            std::copy(in.begin(), in.end(), std::back_inserter(out));
            
            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #7

            @Christian-Ehrlicher Are iterators faster than indexing ([index]) ?

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            1
            • VRoninV VRonin

              Just to clarify: @JohanSolo , @Christian-Ehrlicher and @SGaist 's solutions are correct. My solution should be faster as it's a simple memcpy but the other's might be safer (I don't really see how though)

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #8

              @VRonin

              My solution should be faster as it's a simple memcpy

              Does yours assume 32-bit where the others don't? Is (part of) the question to convert from qint32 to whatever int is, which I assumed is 64-bit now?

              Christian EhrlicherC 1 Reply Last reply
              0
              • JonBJ JonB

                @VRonin

                My solution should be faster as it's a simple memcpy

                Does yours assume 32-bit where the others don't? Is (part of) the question to convert from qint32 to whatever int is, which I assumed is 64-bit now?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @JonB said in How to convert const QVector<quint32> to vector<int>.:

                which I assumed is 64-bit now?

                int is 32 bit, on every platform Qt is running on :)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                JonBJ 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @JonB said in How to convert const QVector<quint32> to vector<int>.:

                  which I assumed is 64-bit now?

                  int is 32 bit, on every platform Qt is running on :)

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #10

                  @Christian-Ehrlicher
                  Wot? Really?? I thought it was 64 on 64....

                  JKSHJ 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Christian-Ehrlicher
                    Wot? Really?? I thought it was 64 on 64....

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by JKSH
                    #11

                    @JonB said in How to convert const QVector<quint32> to vector<int>.:

                    Wot? Really?? I thought it was 64 on 64....

                    Pointer size is increased to 64 but integer size remains 32 on today's common 64-bit desktop architectures.

                    sizeof(qintptr) == sizeof(void*) != sizeof(int)

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    J.HilkJ 1 Reply Last reply
                    3
                    • JKSHJ JKSH

                      @JonB said in How to convert const QVector<quint32> to vector<int>.:

                      Wot? Really?? I thought it was 64 on 64....

                      Pointer size is increased to 64 but integer size remains 32 on today's common 64-bit desktop architectures.

                      sizeof(qintptr) == sizeof(void*) != sizeof(int)

                      J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #12

                      @JKSH said in How to convert const QVector<quint32> to vector<int>.:

                      sizeof(qintptr) == sizeof(void*) != sizeof(int)

                      wow, I totally assumed differently,
                      I should make it habit to use the explicitly size defined qintXX/quintXX in the future...


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      JKSHJ 1 Reply Last reply
                      1
                      • J.HilkJ J.Hilk

                        @JKSH said in How to convert const QVector<quint32> to vector<int>.:

                        sizeof(qintptr) == sizeof(void*) != sizeof(int)

                        wow, I totally assumed differently,
                        I should make it habit to use the explicitly size defined qintXX/quintXX in the future...

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by
                        #13

                        @J-Hilk said in How to convert const QVector<quint32> to vector<int>.:

                        I should make it habit to use the explicitly size defined qintXX/quintXX in the future...

                        Good idea!

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        1 Reply Last reply
                        0
                        • JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #14

                          @JKSH , @J-Hilk

                          Pointer size is increased to 64 but integer size remains 32 on today's common 64-bit desktop architectures.

                          Yes, now I vaguely remember reading this, I am glad @J-Hilk shared my mis-assumption!

                          This is what comes of my being forced to use Python for Qt or JavaScript over so many years now. Ignorance of underlying type sizes! It has been a long time since sizeof(int) != sizeof(long) and sizeof(int) != sizeof(void*), probably not since the initial move from 16-bit to 32-bit architecture! :)

                          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