Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Problem with indexOf



  • Hi

    I seem to be having problem with a QString.indexOf and Case Sensitivity.

    @
    QString s("end = true");
    s.indexOf("End", Qt::CaseInsensitive); // will return a -1 item not found.
    s.indexOf("end", Qt::CaseInsensitive); // will return a 0 which is proper.
    @

    Is there a oversight I'm not seeing or is this a Qt bug?

    OS = Linux, Qt5

    Thanks

    Chris



  • The case sensitivity is the third parameter, not the second:
    @indexOf ( const QString & str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const@

    Regards,
    H.



  • Hey! Thanks, completely overlooked that one, what are the chances that Qt::CaseInsensitive would be a enum that just happened to be a value of 0, no wonder the compiler passed it by.

    Thanks again!!


Log in to reply