Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

QSqlQueryModel + QTableView + QCompleter = filter

$
0
0
hi, I have a lineEdit and a tableView in my form. I would like to create a filter that narrows down the data existing in my database with the text entered in lineEdit; the data is shown in the tableView. the connection to the database is working and tested i have to following code: QSqlQuery q1(g);  // g is my database connection q1.prepare("SELECT * FROM name where stname like ':lEstname'"); q1.bindValue(":lEstname", ui->lEstname->text()); QSqlQueryModel *filter = new QSqlQueryModel(); q1.exec(); filter->setQuery(q1); QCompleter *completerfilter = new  QCompleter (filter); ui->lEstname->setCompleter(completerfilter); ui->tableView->setModel(filter); when I run, the result is the model columns headers with no data resulted from the query, just the headers, because the query is executed before I enter the text, basically with lEstname empty. expected result would be: have all possible text entry shown in lEstname, with the QCompleter and query results entered in tableView. what I’m doing wrong? thanks

Viewing all articles
Browse latest Browse all 13965

Trending Articles