Reputation: 662
I have a QlineEdit and a QTableView in a simple program.
I load a table (for example person) from SQLite to tableView.
I want an event or anything else that as I type in lineEdit the tableView change based on it.
For example if the the table person have a field name that filled by:
I want when I press "m" all the name that started with "m", like mehran, mehsa, mahid show on the tableView. And when I press next key for example "e", just mehran and mehsa show on tableView, and so on.
Upvotes: 1
Views: 362
Reputation: 53205
You would need to do a connection like this based on this signal:
connect(lineEdit, &QLineEdit::textChanged, [=](const QString &string) {
QSqlQuery query(QString("SELECT %1 FROM ..").arg(string));
while (query.next()) {
QStringList stringList = query.value(0).toStringList();
updateTableView(stringList);
}
});
At this point in time, you will also need to add the following line in your qmake project file to get the new signal-slot syntax:
CONFIG += c++11
Upvotes: 1