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. Best way to do pattern matching in QList
Forum Updated to NodeBB v4.3 + New Features

Best way to do pattern matching in QList

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • B Offline
    B Offline
    BasicPoke
    wrote on last edited by
    #1

    Hello, I need to match a pattern of about length 10, in a QList<qint8> of about size 50. All elements are either 0 or 1. The pattern may exist multiple times and I may need to find all of them. Any suggestions how to do this easily? I am not finding any QList compare functions.

    Currently I am doing the following, but not very convenient:

    @ for( int i=0; i<bits.size()-10; i++ )
    {
    if( bits.at(i)==0 && bits.at(i+1)==0 && bits.at(i+2)==0 && bits.at(i+3)==0
    && bits.at(i+4)==0 && bits.at(i+5)==0 && bits.at(i+6)==0 && bits.at(i+7)==0
    && bits.at(i+8)==1 && bits.at(i+9)==0 )
    ...
    @
    Thanks
    Ron

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BlastDV
      wrote on last edited by
      #2

      That's actually doing the job but if you want to save code or do it someway different, you could try:

      Create an empty QString

      Create a for to iterate trough all 10 values

      On every iteration, append the current value to you QString

      After the for ends, compare whatever pattern you want with your QString.

      @
      if (QString==QString)
      {
      // your code
      }
      @

      This may look longer to code, but it will allow you to compare what you have with any pattern, as well as they are the same size.

      (8) Just live your life blind like me (8)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BasicPoke
        wrote on last edited by
        #3

        That is a good idea BlastDV. Maybe there is some easy way to compare a QList to a section of another QList.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BlastDV
          wrote on last edited by
          #4

          I'm also interested to know. Let's see if some other idea pops up!

          (8) Just live your life blind like me (8)

          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