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. Split binary sequence into more buffers (QByteArray).

Split binary sequence into more buffers (QByteArray).

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 694 Views
  • 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.
  • S Offline
    S Offline
    simozz
    wrote on last edited by simozz
    #1

    I have a QByteArrary that I fill from a stream, more precisely the data are JPEG encoded frame (SOI = 0xffd8, EOI = 0xffd9), one after the other.

    QByteArrary::split method only allow to search for a char character and not for a char * data type. Is there another way to look for a determined sequence in an a binary buffer ?

    Of course I can develope my own function, but if there is something alredy done it would be perfect.

    Thanks in advance.
    Regards,
    s.

    jsulmJ 1 Reply Last reply
    0
    • S simozz

      I have a QByteArrary that I fill from a stream, more precisely the data are JPEG encoded frame (SOI = 0xffd8, EOI = 0xffd9), one after the other.

      QByteArrary::split method only allow to search for a char character and not for a char * data type. Is there another way to look for a determined sequence in an a binary buffer ?

      Of course I can develope my own function, but if there is something alredy done it would be perfect.

      Thanks in advance.
      Regards,
      s.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @simozz You can use https://doc.qt.io/qt-5/qbytearray.html#indexOf-1 and then https://doc.qt.io/qt-5/qbytearray.html#mid
      But this is a bit more work as just using split().

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3
            const unsigned char soi[]={0xff,0xd8,0};
            const unsigned char eoi[]={0xff,0xd9,0};
            const int startOfItem = dataArray.indexOf(reinterpret_cast<const char*>(soi));
            const int endOfItem = dataArray.indexOf(reinterpret_cast<const char*>(eoi),startOfItem);
            if(startOfItem>0 && endOfItem>0)
            qDebug() << dataArray.mid(startOfItem,endOfItem-startOfItem+1).toBase64();
        

        "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
        5
        • S Offline
          S Offline
          simozz
          wrote on last edited by
          #4

          Thank you guys for your help. : )

          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