Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading database table content into a text edit

Reading database table content into a text edit

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 988 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

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

    raven-worxR 1 Reply Last reply
    0
    • L Lasith

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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      L 1 Reply Last reply
      0
      • raven-worxR raven-worx

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

        L Offline
        L Offline
        Lasith
        wrote on last edited by
        #3

        @raven-worx yes it has to show all rows

        raven-worxR 1 Reply Last reply
        0
        • L Lasith

          @raven-worx yes it has to show all rows

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

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

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved