Bug 309779 - QLineEdit clear signal not clearing text
Summary: QLineEdit clear signal not clearing text
Status: RESOLVED UNMAINTAINED
Alias: None
Product: Necessitas
Classification: Applications
Component: Android Qt4 (show other bugs)
Version: alpha4
Platform: Android Android 4.x
: NOR normal
Target Milestone: Unspecified
Assignee: BogDan Vatra
URL: http://stackoverflow.com/questions/13...
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-08 23:17 UTC by Chris Dargis
Modified: 2018-09-04 16:16 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dargis 2012-11-08 23:17:55 UTC
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.
Comment 1 tomaslov 2013-01-01 21:00:27 UTC
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.
Comment 2 Andrew Crouthamel 2018-09-04 16:16:54 UTC
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.