简体   繁体   English

在QLineEdit中输入内容进行实时更改

[英]live changing as typing in QLineEdit

I have a QlineEdit and a QTableView in a simple program. 我在一个简单的程序中就有一个QlineEdit和QTableView。

I load a table (for example person) from SQLite to tableView. 我从SQLite加载表(例如人)到tableView。

I want an event or anything else that as I type in lineEdit the tableView change based on it. 我想要一个事件或当我在lineEdit中键入的其他任何内容时,tableView会基于此更改。

For example if the the table person have a field name that filled by: 例如,如果表人的字段名称由以下内容填充:

  1. mehran 迈赫兰
  2. mehsa mehsa
  3. mahid mahid
  4. naser 纳塞尔
  5. omid OMID

I want when I press "m" all the name that started with "m", like mehran, mehsa, mahid show on the tableView. 我想在按“ m”时所有以“ m”开头的名称,例如在tableView上显示mehran,mehsa,mahid。 And when I press next key for example "e", just mehran and mehsa show on tableView, and so on. 当我按下下一个键(例如“ e”)时,只有mehran和mehsa显示在tableView上,依此类推。

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: 此时,您还需要在qmake项目文件中添加以下行以获得新的信号插槽语法:

CONFIG += c++11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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