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. qbytearray find two similar values

qbytearray find two similar values

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 541 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.
  • faduF Offline
    faduF Offline
    fadu
    wrote on last edited by fadu
    #1

    hi i have data like this
    "8800010026020000086A54161565415621" + some another data + "8800010026020000083A352303661445"
    i want to find the two index start with "8800010026020000"

     QFile file("somthing");
        file.open(QIODevice::ReadOnly);
        QByteArray data = file.readAll();
        file.close();
        QByteArray patch_data1 = QByteArray::fromHex("8800010026020000");
        int64_t index = data.indexOf(patch_data1);
        qInfo() <<data.mid(index,16).toHex();
    
    JonBJ 1 Reply Last reply
    0
    • faduF fadu

      @JonB
      yes that's what i mean but it's return the first value only

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

      @fadu
      qsizetype QByteArray::indexOf(QByteArrayView bv, qsizetype from = 0) const takes an optional second parameter where you tell it to start the search from.

      1 Reply Last reply
      1
      • faduF fadu

        hi i have data like this
        "8800010026020000086A54161565415621" + some another data + "8800010026020000083A352303661445"
        i want to find the two index start with "8800010026020000"

         QFile file("somthing");
            file.open(QIODevice::ReadOnly);
            QByteArray data = file.readAll();
            file.close();
            QByteArray patch_data1 = QByteArray::fromHex("8800010026020000");
            int64_t index = data.indexOf(patch_data1);
            qInfo() <<data.mid(index,16).toHex();
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @fadu
        You have the first match. So go ahead and search after that for the second match, is that what you mean?

        1 Reply Last reply
        0
        • faduF Offline
          faduF Offline
          fadu
          wrote on last edited by fadu
          #3

          @JonB
          yes that's what i mean but it's return the first value only

          JonBJ 1 Reply Last reply
          0
          • faduF fadu

            @JonB
            yes that's what i mean but it's return the first value only

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

            @fadu
            qsizetype QByteArray::indexOf(QByteArrayView bv, qsizetype from = 0) const takes an optional second parameter where you tell it to start the search from.

            1 Reply Last reply
            1
            • faduF Offline
              faduF Offline
              fadu
              wrote on last edited by
              #5

              @JonB
              that's it thanks a lot
              the problem is solved and this is the new code

                QFile file("test.qcn");
                  file.open(QIODevice::ReadOnly);
                  QByteArray data = file.readAll();
                  file.close();
                  QByteArray patch_data1 = QByteArray::fromHex("8800010026020000");
                  int64_t index = data.indexOf(patch_data1);
                  int64_t index2 = data.indexOf(patch_data1,index+patch_data1.size());
                  qInfo() <<data.mid(index,17).toHex()<<index<< data.mid(index2,17).toHex() << index2;
              
              1 Reply Last reply
              1

              • Login

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