Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED] How to display an SQLite table in Qt without the ability to change its content ?

    General and Desktop
    2
    4
    781
    Loading More Posts
    • 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.
    • Y
      ysing last edited by

      Hello,

      I wrote the following code to display an SQlite table and the table appears after execution .

      My problem is that I don't want to make changes to my table which is not the case here as after execution I can make modifications to the existing table.

      @void myFunction::on_pushButton_clicked()
      {
      homepage conn;
      QSqlQueryModel *model = new QSqlQueryModel();

      conn.connOpen();
      QSqlQuery *qry = new QSqlQuery(conn.mydb);
      
      qry->prepare("SELECT * from table");
      
      qry->exec();
      
      model->setQuery(*qry);
      
      ui->tableView->setModel(model);
      
      conn.connClose();
      qDebug() <<(model->rowCount());
      

      }
      @

      Thanks.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Call setEditTriggers with QAbstractItemView::NoEditTriggers on your view and it will be read-only.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Y
          ysing last edited by

          SGaist thank you very much it worked .

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            You're welcome !

            Since you have your widget working correctly now, please update the thread tittle prepending [solved] so other forum users may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post