How to store the text entered in LineEdit?
-
I am a new bie to Qt. I hope you guys can help me to solve my problem. I want to store (save) the user entered text of a QLineEdit. I want to store this in a string list. Also i have to check whether the user entered text is already stored. If the text is already stored then it should not store again. Please help...
-
You can add a QLineEdit and QPushButton in your mainwindow and connect the QPushButton clicked() signal to a slot.
@void MainWindow::on_addButton_clicked()
{
QString text = ui->lineEdit->text();if (!list.contains(text)) list.append(text);
}@
You can also check for CaseSensitivity.
-
Well, Qt is great is doing something like that.
Connect the signal of the LineEdit editingFinished() to a slot in your class (probably your main window.
@
connect(ui->lineEditName, SIGNAL(editingFinished()), this, SLOT(MyReceivingSlot())
@
btw: the ui-> comes from the designer created widget.The code for that slot:
@
void MainWindow::MyReceivingSlot(void)
{
if (m_MyList.contains(ui->lineEditName.text()) == false)
{
m_MyList.apped(ui->lineEditName.text();
}
}
@
Of course the m_MyList is a member of the MainWindow class.
btw the MyReceivingSlot must be a slot and not a standard private or public function. (just saying it because your a rooky here ;-))
That is basic how you could do it.
Greetz -
If this answered your question, edit your post and add [SOLVED] to the title.