[英]Display data real time in QT c++ from db
像這樣
該項目有一個具有以下架構的頁面:
有一個整數 QlineEdit 和一個 texBox(或可以使用另一個小部件)我想在文本框中顯示數據庫的相關單元格(帶有查詢的 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);
希望有用;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.