Example of subclassing QSqlTableModel?
-
I am new to Qt (coming from iOS programming) and am doing an image viewer app as a learning project.
I have a
QListView
backed by aQSqlTableModel
, 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 subclassQSqlTableModel
and 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
QSqlTableModel
? -
Hi,
You could always take a look at QSqlRelationalTableModel
Constructor example:
@
mytablemodel.h
class MyTableModel : public QSqlTableModel
{
public:
explicit MyTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase() ); // the same arguments as QSqlTableModel
};mytablemodel.cpp
MyTableModel::MyTableModel(QObject * parent, QSqlDatabase db) :
QSqlTableModel(parent, 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 modelHope it helps