简体   繁体   中英

live changing as typing in QLineEdit

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:

  1. mehran
  2. mehsa
  3. mahid
  4. naser
  5. omid

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM