Important: Please read the Qt Code of Conduct -

Possible bug in QString::replace

  • I'm new to QT so I don't want to file bug reports unnecessarily. Maybe this is fixed. Maybe I am missing something.

    I believe I am running version 5.4. I see this code at the beginning of QString::replace

    QString& QString::replace(const QRegExp &rx, const QString &after)
    QRegExp rx2(rx);

    if (isEmpty() && rx2.indexIn(*this) == -1)
        return *this;

    Unless I am making a stupid mistake, that "&&" should be "||".
    The line is saying that if the string is empty and does not contain the search string, then return. Of course, if the string is empty, we already know it does not contain the search string. I would think that we would want to return if the string is empty or it does not contain the search string.

  • Hi and welcome to devnet

    Without doing additional research on this, I can follow your arguments. That does not seem to be correct.

    You can check for bug reports on JIRA. This would be also the place to file a bug report yourself.

  • Correction. I believe I am running version 5.1

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    It's still present in 5.5

  • I just reported it.

    It will be interesting to see the response. Last time I reported an issue showing the actual code that was wrong was many years ago with the MFC. Even being handing the exact line of code and the exact fix, 5 years later it was still there. But I digress.

  • Lifetime Qt Champion

    Thanks, don't forget to share the link to the report, so other user can find it more easily.

  • I hope you cannot compare MS with opensource, but you are right that will interesting.

    As SGaist is suggesting, it is good to provide a link to the bug report here. This allows easier finding the report and its status. Furthermore, it helps also because others can vote for it. In the turn-around this may prevent the experience you had with MFC ;)

Log in to reply