Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86580

QComboBox::setPlaceholderText() has side-effects, changes currentText

    XMLWordPrintable

Details

    • 789d487cb0f4ef6f9d3e7c6ab5c5283dfe8dd350 (qt/qtbase/dev) 0790249acf069d89f6debc98eab4caf5b8ca2712 (qt/qtbase/5.15)

    Description

      QComboBox::setPlaceholderText() was introduced in 5.15, but has the following bug:
      When using it, QComboBox::currentText() will change.
      This is unexpected and different than the QLineEdit behaviour.

      The placeholder text should never leak out, as it's not data, it's just a visual aid.

      #include <QDebug>
      #include <QApplication>
      #include <QComboBox>
      #include <QLineEdit>
      
      int main(int a, char **b) {
      
          QApplication app(a, b);
      
          QLineEdit l;
          l.setPlaceholderText("foo");
      
          QComboBox c;
          c.setPlaceholderText("foo");
      
          qDebug()  << c.currentText() << l.text(); // Prints "foo" ""
      
          return 0;
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-86580
        # Subject Branch Project Status CR V

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            iamsergio Sergio Martins
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes