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. Convert QByteArray to vector<uint8_t>
Forum Updated to NodeBB v4.3 + New Features

Convert QByteArray to vector<uint8_t>

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.9k 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.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by Damian7546
    #1

    Hi,

    I need help with convert QByteArray to vector<uint8_t>.
    Is there any simple way to do it ?

    JonBJ M 2 Replies Last reply
    0
    • D Damian7546

      Hi,

      I need help with convert QByteArray to vector<uint8_t>.
      Is there any simple way to do it ?

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

      @Damian7546
      Does this work:

      std::vector<uint8_t> c(bytes.constData(), bytes.constData() + bytes.size());
      

      uint8_t should be same type as unsigned char.

      M JoeCFDJ 2 Replies Last reply
      3
      • D Damian7546

        Hi,

        I need help with convert QByteArray to vector<uint8_t>.
        Is there any simple way to do it ?

        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        Hi,

        something like this:

        for(const char c : array)
            vector<<uint8_t(c);
        
        JonBJ 1 Reply Last reply
        0
        • M mpergand

          Hi,

          something like this:

          for(const char c : array)
              vector<<uint8_t(c);
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @mpergand
          That's really slow! Surely this is worth doing (somehow) without iterating?

          1 Reply Last reply
          0
          • JonBJ JonB

            @Damian7546
            Does this work:

            std::vector<uint8_t> c(bytes.constData(), bytes.constData() + bytes.size());
            

            uint8_t should be same type as unsigned char.

            M Offline
            M Offline
            mpergand
            wrote on last edited by
            #5

            @JonB said in Convert QByteArray to vector<uint8_t>:

            std::vector<uint8_t> c(bytes.constData(), bytes.constData() + bytes.size());

            Good catch,
            does not seem possible with QVector ?

            JonBJ 1 Reply Last reply
            0
            • D Damian7546 has marked this topic as solved on
            • M mpergand

              @JonB said in Convert QByteArray to vector<uint8_t>:

              std::vector<uint8_t> c(bytes.constData(), bytes.constData() + bytes.size());

              Good catch,
              does not seem possible with QVector ?

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

              @mpergand
              Sorry, not sure what you mean? You mean that code would not work to convert to QVector<uint8_t> instead of std::vector<uint8_t>, is that it?

              1 Reply Last reply
              0
              • JonBJ JonB

                @Damian7546
                Does this work:

                std::vector<uint8_t> c(bytes.constData(), bytes.constData() + bytes.size());
                

                uint8_t should be same type as unsigned char.

                JoeCFDJ Offline
                JoeCFDJ Offline
                JoeCFD
                wrote on last edited by JoeCFD
                #7

                @JonB nice solution. Is std::vector<uint8_t> c( bytes.begin(), bytes.end() ) more C++ style-ish?;

                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