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



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


  • Lifetime Qt Champion

    Hi,

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



  • SGaist thank you very much it worked .


  • Lifetime Qt Champion

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


Log in to reply
 

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