mainwindow.h class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); public slots: void slotClear(); private: QLineEdit* line1; QLineEdit* line2; //... }; mainwindow.cpp MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QVBoxLayout* mainLayout = new QVBoxLayout; QFormLayout* form = new QFormLayout; line1 = new QLineEdit; form->addRow(tr("Line 1: "), line1); line2 = new QLineEdit; form->addRow(tr("Line 2:"), line2); QPushButton* button = new QPushButton; mainLayout->addLayout(form); mainLayout->addWidget(button); QWidget* centralWid = new QWidget(this); centralWid->setLayout(mainLayout); this->setCentralWidget(centralWid); connect(button, SIGNAL(clicked()), this, SLOT(slotClear())); } void MainWindow::slotClear() { line1->clear(); line2->clear(); } //... This code is set-up to clear the text in two QLineEdit objects when a button is clicked. Unfortunately this isn't the case, randomly only one of the two QLineEdit objects are cleared. Additionally entering text in one line, switching to another line and entering text there, and then switching back to the original line results in the original text being erased once the field is clicked (note, the button was never clicked). Reproducible: Always Steps to Reproduce: 1. Create a new project 2. Add two QLineEdit objects and a QPushButton object to a main window 3. Connect the QPushButton clicked() signal to the QLineEdit objects clear() slots. 4. Run the application, enter text in both QLineEdit objects and click the button. Actual Results: Both QLineEdit objects are not cleared of text. Expected Results: Both QLineEdit objects should have no text. Calling the function QLineEdit::setText("") with an empty string has the same results.
This is quite probably a duplicate of the reported bug https://bugs.kde.org/show_bug.cgi?id=307748. If so, a known workaround is to disable predictive text on the device keyboard settings. Then QLineEdit works ok on getting and clearing text. As for now when this bug still exists, only one of the following will help you get correct results when setting, getting and clearing text in multiple QLineEdits - and predictive text is enabled on the device: 1. the user presses "space" after last word inputed 2. the user presses "done" after last word inputed 3. the user selects one of the suggested words from predictive text as last word inputed.
Hello! Sorry to be the bearer of bad news, but this project has been unmaintained for many years and I will be closing this bug.