Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
4.5.2
-
None
-
2d750192e73244f5b4ad6b451f264728d42669be
Description
Steps to reproduce / test case:
If you set as a source model a QSqlQueryModel which has no query set yet (or any other empty model, I assume), and then use setHeaderData() on the source model, the application crashes.
Example code:
#include <QApplication>
#include <QSqlQueryModel>
#include <QSortFilterProxyModel>
// connection.h from Qt/examples/sql
#include "../connection.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (!createConnection())
return 1;
QSqlQueryModel plainModel;
QSortFilterProxyModel proxyModel;
proxyModel.setSourceModel(&plainModel);
// next line causes the crash
plainModel.setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
// setting the query before the header data works...
plainModel.setQuery("select * from person");
plainModel.setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
return 0;
}
More information:
The attached image shows where the crash occurs. No validation is done before accessing the vector.