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. [Solved]How to use multiple expressions to find matches in QString::endsWith( const QString &, Qt::CaseSensitivity) function?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How to use multiple expressions to find matches in QString::endsWith( const QString &, Qt::CaseSensitivity) function?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.0k 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.
  • S Offline
    S Offline
    SetBetterPass
    wrote on last edited by
    #1

    I have list of urls I need find out urls pointing at pictures, I have this code but my problem is it always returns false so no match in list is found (there are 5 matches in my actual list), I tryed it with QRegExp but there is no function QString::endsWith(QRegExp) or something. I see the problem is with multiple expressions because it works ok if fileType=".png". I go afk for longer time now so if you can help it could be nice so I can continue with work when i come back. Thanks :)
    @
    int a,b;
    QString string,fileType="(.jpg|.gif|.png|.jpeg|.bmp|.tif|.tiff|.swg|.ico)";
    while(a<UrlList.count()){
    string=UrlList[a];
    if (string.endsWith(fileType, Qt::CaseInsensitive) == 1){ //there is my problem
    FileList.append(string); //this list I'll need later
    UrlList[b]=UrlList[a]; //pushing urls ill need to 1st places in list
    b++;
    }
    a++;
    if(a>=UrlList.count()){while(b<UrlList.count()){UrlList.removeAt(b);}break;} //to remove unneeded urls
    }@

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Serenity
      wrote on last edited by
      #2

      Your program thinks, your type ends with the long string.
      I would do it that way:
      [code]
      for(int i=0;i<fileType.split("|").count();i++) {
      if (string.endsWith(fileType.split("|").at(i), Qt::CaseInsensitive) == 1){
      FileList.append(string); //this list I'll need later
      UrlList[b]=UrlList[a]; //pushing urls ill need to 1st places in list
      b++;
      }
      }[/code]
      or something like that.
      split create a QStringList and splits your string. Go through the list and check every file seperately with every fileend.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SetBetterPass
        wrote on last edited by
        #3

        Thanks it worked :)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          That will fail for ".jpg" and ".ico" files. Further, you're not initializing all your local variables a and b, I'm wondering how it could've ever worked consistently.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Serenity
            wrote on last edited by
            #5

            Yes, that's right, thank you DerManu :)

            Please change
            [code]QString string,fileType="(.jpg|.gif|.png|.jpeg|.bmp|.tif|.tiff|.swg|.ico)";[/code]
            to
            [code]QString string,fileType=".jpg|.gif|.png|.jpeg|.bmp|.tif|.tiff|.swg|.ico";[/code]

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SetBetterPass
              wrote on last edited by
              #6

              yes I noticed it right after I read "Your program thinks, your type ends with the long string." so I removed it. And a and b were initialized somewhere else in program so I just typed it there forgot "=0" but in program its @int a=0,b=0;@

              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