Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Example of subclassing QSqlTableModel?
A Former User last edited by
I am new to Qt (coming from iOS programming) and am doing an image viewer app as a learning project.
I have a
QListViewbacked by a
QSqlTableModel, and instead of images names, I want to display thumbnails. I've seen "here":http://www.qtcentre.org/threads/37895-How-to-show-images-from-database-as-icons-in-QListView that one way to do it is to subclass
QSqlTableModeland override the data() method. I understand this conceptually and have read "Model Subclassing Reference":http://www.trinitydesktop.org/docs/qt4/model-view-model-subclassing.html and also searched around but have not found a barebones example of, for instance, how to implement the constructor in my subclass. Most examples assume that one knows this most basic thing (I guess).
Can someone post (or point me to) a barebones example .h and .cpp showing how to subclass
You could always take a look at QSqlRelationalTableModel
class MyTableModel : public QSqlTableModel
explicit MyTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase() ); // the same arguments as QSqlTableModel
MyTableModel::MyTableModel(QObject * parent, QSqlDatabase db) :
// the rest of your code
Subclassing in Qt is exactly the same as for any other C++ class.
But before going this way, are you getting your images from the database ?
You might also consider implementing a QStyledItemDelegate to show what you want rather than modify the model
Hope it helps