Hello,
Following Qt model-view pattern, I created a "MyModel" class.
The library I'm working with retrieves data from a store and gives me a list of XImageObjectPtr, these are shared pointers (typedef... QSharedPointer).
The underlying object has some string or binary properties.
Can I use them as is to populate my QListView ? I tried, but get exception when I start my app... However I'm unable to find out the relevant information in crash log.
So my question is about direct use of QSharedPointer as a QListView item.
My model header:
{
Q_OBJECT
public:
DicomImageModel
(QObject *parent
= 0);
void addImage(const XImageObjectPtr image);
private:
std::vector<XImageObjectPtr> m_dicomImages;
};
class DicomImageModel : public QAbstractTableModel
{
Q_OBJECT
public:
DicomImageModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void addImage(const XImageObjectPtr image);
private:
std::vector<XImageObjectPtr> m_dicomImages;
};
To copy to clipboard, switch view to plain text mode
and:
Use of this model:
DicomImageModel model;
foreach (XObjectPtr obj, XContainer::instance()->findObjectsByClass(XObject::Image)) {
XImageObjectPtr image = obj.dynamicCast<XImageObject>();
xLogWarning(XLogRecord::Type_User, tr("ID: %1").arg(image->getId()));
model.addImage(image);
}
m_listview->setModel(&model);
m_mainWidget->layout()->addWidget(m_listview);
DicomImageModel model;
foreach (XObjectPtr obj, XContainer::instance()->findObjectsByClass(XObject::Image)) {
XImageObjectPtr image = obj.dynamicCast<XImageObject>();
xLogWarning(XLogRecord::Type_User, tr("ID: %1").arg(image->getId()));
model.addImage(image);
}
m_listview->setModel(&model);
m_mainWidget->layout()->addWidget(m_listview);
To copy to clipboard, switch view to plain text mode
Thank you
Bookmarks