简体   繁体   English

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

[英]Display data real time in QT c++ from db

Sth like this这样

The project has a page with this schema:该项目有一个具有以下架构的页面:

There is a QlineEdit in integer and a texBox(or can be use another widget) I want to Display the relevant cell of database(sqlite with query for example:select * frome dbName where code='QlineEdit integer') in textBox, But no with a button action, real time!有一个整数 QlineEdit 和一个 texBox(或可以使用另一个小部件)我想在文本框中显示数据库的相关单元格(带有查询的 sqlite 例如:select * frome dbName where code='QlineEdit integer'),但没有一个按钮动作,实时!

As I search it can be possible by textchange() or QLineEdit::editingFinished(), But don't know how在我搜索时可以通过 textchange() 或 QLineEdit::editingFinished() 来实现,但不知道如何

It works like this for the who one later see:对于后来看到的人来说,它是这样工作的:

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);

Hope useful;希望有用;

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

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