InsertRow
-
i don't know what is model and you can show me how to insert a new row and add data to every cell of new row ? I just want this but i don't know how to do it.
@Duy-Khang
Nobody can without knowing what model you are using. Only you know that, and you really should know what your model is. Have you tried reading the Model/View Tutorial? -
We all understood what you want to do.
What we are asking you is what type of model is set on that QTableView ?
QSqlTableModel ?
QSqlQueryModel ?
QStandardItemModel ?
Custom QAbstractTableModel based model ?
Other ? (to be defined) -
@Duy-Khang
At last! AQSqlQueryModel
is for querying SQL, it does not allow insertions, because it does not know where to insert any rows. It sounds like you should switch to aQSqlTableModel
for inserts etc.? I assume the rows you show are all in one table, which is where you want to insert/update/delete rows. -
@Duy-Khang
The code you showed would work if the model is aQSqlTableModel
instead of aQSqlQueryModel
, and you have specified the table. You can search https://doc.qt.io/qt-5/qsqltablemodel.html and https://doc.qt.io/qt-5/qsqltablemodel-members.html forinsertRow
and see what you come across. There is alsoQSqlTableModel::insertRecord()
etc. if you prefer a record-based interface to a row-based interface, that is a matter of preference.BTW you don't need to worry about/implement the
beginInsertRows()
etc. you asked about if you use aQSqlTableModel
, its implementation handles that for you. -
@Duy-Khang
Please read the documentation rather than asking each time. It is beneficial to you to understand, not just be told. There is even an example at https://doc.qt.io/qt-5/qsqltablemodel.html#details. -
@Duy-Khang
Please read the documentation rather than asking each time. It is beneficial to you to understand, not just be told. There is even an example at https://doc.qt.io/qt-5/qsqltablemodel.html#details. -
@Duy-Khang said in InsertRow:
do you know how to disable or turn off the these indexs in this picture ?
Hide the horizontal and vertical header.
-
@Duy-Khang
If that column is in the table but you don't want to show it, use void QTableView::hideColumn(int column) to suppress it in your view.Oh, I misunderstood what you were wanting to hide in your picture! I thought you meant the first column!
In which case it's the horizontal header as @Christian-Ehrlicher has pointed you to.
-
@Duy-Khang said in InsertRow:
do you know how to disable or turn off the these indexs in this picture ?
Hide the horizontal and vertical header.
@Christian-Ehrlicher thank you.
-
@Duy-Khang
If that column is in the table but you don't want to show it, use void QTableView::hideColumn(int column) to suppress it in your view.Oh, I misunderstood what you were wanting to hide in your picture! I thought you meant the first column!
In which case it's the horizontal header as @Christian-Ehrlicher has pointed you to.
-
@Duy-Khang
If that column is in the table but you don't want to show it, use void QTableView::hideColumn(int column) to suppress it in your view.Oh, I misunderstood what you were wanting to hide in your picture! I thought you meant the first column!
In which case it's the horizontal header as @Christian-Ehrlicher has pointed you to.
-
What names do you want there ?
-
The same as usual.
As for setting the header data, it's shown in the QSqlTableModel documentation.