从数据库实时显示QT c++中的数据

Display data real time in QT c++ from db

本文关键字:数据 c++ QT 数据库 实时 显示      更新时间:2023-10-16

像这个一样

该项目有一个具有以下模式的页面:

有一个QlineEdit in integer和一个texBox(或者可以使用另一个小部件(我想在textBox中显示数据库的相关单元格(sqlite带查询,例如:select*frome dbName where code='QlineEdit integer'(,但不需要按钮操作,实时!

当我搜索时,它可以通过textchange((或QLineEdit::editingFinished((实现,但不知道是如何实现的

它的工作原理是这样的,稍后会看到:

connect(ui->nameLine,SIGNAL(textChanged(QString)),this,
SLOT(updateLineEditText(QString)));
void MainWindow::updateLineEditText(QString cd) {
ui->nameLabel->setText("");
QString textEditString(cd);
QString flname;
MainWindow conn;
conn.connopen();
QSqlQuery query;
query.exec("SELECT Firstname, Lastname, Code  FROM Election WHERE Code='"+cd+"'");
while (query.next()) {
flname.append( query.value(0).toString() + " ");
flname.append( query.value(1).toString() + " ");
ui->nameLabel->setText(flname);

希望有用;