Find an occurrence in a QList



  • Hello,
    im looking to find a way of an occurance of a string inside a QList<Qstring>.
    this is what i did:

    i declare a string str1
    i have a QList of strings List1 where i stock some QStrings that i receive.
    and i use the the methode contains as i do here: list1.contains(str1)
    but i dont know if i it returns true for the exact match or just a substring .

    thank you.



  • QList.contains() should only return true for case sensitive exact matches.

    QString strInstance = QString("Quick Test");
    
    listOStrings.append(strInstance);
    
    listOStrings.contains("Quick") // Returns False
    listOStrings.contains("quick test") // Returns False
    listOStrings.contains("Quick Test") // Returns True
    listOStrings.contains(strInstance) // Returns True
    

    Hope this helps.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.