Unsolved Reading database table content into a text edit
-
The following code is used by me to read database table contents into a Qtableview but the setmodel is not working for Lineedit! How can I display the same contents in the lineedit?
void EmployeeInfo::on_pushButton_3_clicked()
{
Login conn;
QSqlQueryModel * modal = new QSqlQueryModel();
conn.connOpen();
QSqlQuery* qry = new QSqlQuery(conn.mydb);
qry->prepare("select uname from einfo");
qry->exec();
modal->setQuery(*qry);
ui->tableView->setModel(modal); //working properly
ui->textEdit->setmodel(modal); //not working becauese textedits dont support setmodel()conn.connClose();
}
Here the Conn object is used to provide the necessary database connection( it is working properly!) -
@Lasith
what is the text edit supposed to show? All rows returned by the query? -
@raven-worx yes it has to show all rows
-
@Lasith
then you need to construct the string yourself. Either traverse the query or the model's rows directly and set it to the textedit. -
@Lasith are you sure that all the rows returned by query should show in QTextEdit object? It doesn't look the better widget for the job...