QSqlQueryModel downcasting problem !
-
class Model : public QSqlQueryModel { QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const; }; QSqlQueryModel *model = new QSqlQueryModel(); model->setQuery("select * from table"); Model *derived = static_cast<QSqlQueryModel*>(model ); ui->tableView->setModel(derived); //not working
-
@_compiler said:
HiModel *derived = static_cast<QSqlQueryModel*>(model ); Should it not be Model *derived = static_cast<Model *>(model );
?
-
Hi,
To add to @mrjj, it should be
qobject_cast
-
Model *derived = static_cast<QSqlQueryModel*>(model);
This isn't a valid cast because you can't implicitly cast to a derived type (see @mrjj's comment).
Model *derived = static_cast<Model *>(model);
Is valid but unsafe, as @SGaist pointed out.
Ultimately, what is not working?