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();
    QSqlQuery* qry = new QSqlQuery(conn.mydb);
    qry->prepare("select uname from einfo");
    ui->tableView->setModel(modal); //working properly
    ui->textEdit->setmodel(modal); //not working becauese textedits dont support setmodel()


    Here the Conn object is used to provide the necessary database connection( it is working properly!)

  • Moderators

    what is the text edit supposed to show? All rows returned by the query?

  • @raven-worx yes it has to show all rows

  • Moderators

    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...

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.