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. [SOLVED] How to display an SQLite table in Qt without the ability to change its content ?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 980 Views
  • 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 Offline
    Y Offline
    ysing
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • Y Offline
        Y Offline
        ysing
        wrote on last edited by
        #3

        SGaist thank you very much it worked .

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0

          • Login

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