Examples/Sql/Masterdetail: Fix deleting rows
Completely deleting a row in a QSqlTableModel needs a call to select() afterwards, otherwise a blank column will stay according the documentation of QSqlTableModel::removeRows() Also add albumdetails.xml to the resource file to make sure it's found during runtime. Pick-to: 6.8 Task-number: QTBUG-128434 Change-Id: Ie5cc38edfa27984d186467e3372b05987f78d14c Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
parent
48753a03de
commit
5a28fe86af
@ -32,6 +32,7 @@ target_link_libraries(masterdetail PRIVATE
|
||||
set(masterdetail_resource_files
|
||||
"images/icon.png"
|
||||
"images/image.png"
|
||||
"albumdetails.xml"
|
||||
)
|
||||
|
||||
qt_add_resources(masterdetail "masterdetail"
|
||||
|
@ -173,6 +173,7 @@ void Dialog::increaseAlbumCount(const QModelIndex &artistIndex)
|
||||
|
||||
int albumCount = albumCountIndex.data().toInt();
|
||||
artistModel->setData(albumCountIndex, QVariant(albumCount + 1));
|
||||
artistModel->submitAll();
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,7 +14,7 @@ int main(int argc, char *argv[])
|
||||
if (!createConnection())
|
||||
return EXIT_FAILURE;
|
||||
|
||||
QFile albumDetails("albumdetails.xml");
|
||||
QFile albumDetails(":/albumdetails.xml");
|
||||
MainWindow window("artists", "albums", &albumDetails);
|
||||
window.show();
|
||||
return app.exec();
|
||||
|
@ -202,6 +202,8 @@ void MainWindow::removeAlbumFromFile(int id)
|
||||
void MainWindow::removeAlbumFromDatabase(const QModelIndex &index)
|
||||
{
|
||||
model->removeRow(index.row());
|
||||
// to avoid a blank row, see QSqlTableModel::removeRows()
|
||||
model->select();
|
||||
}
|
||||
|
||||
void MainWindow::decreaseAlbumCount(const QModelIndex &artistIndex)
|
||||
@ -217,6 +219,7 @@ void MainWindow::decreaseAlbumCount(const QModelIndex &artistIndex)
|
||||
showImageLabel();
|
||||
} else {
|
||||
artists->setData(albumCountIndex, QVariant(albumCount - 1));
|
||||
artists->submitAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,5 +2,6 @@
|
||||
<qresource>
|
||||
<file>images/icon.png</file>
|
||||
<file>images/image.png</file>
|
||||
<file>albumdetails.xml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
x
Reference in New Issue
Block a user