Is it OK to use QSharedPointer in QListView?
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:
Code:
{
Q_OBJECT
public:
DicomImageModel
(QObject *parent
= 0);
void addImage(const XImageObjectPtr image);
private:
std::vector<XImageObjectPtr> m_dicomImages;
};
and:
Use of this model:
Code:
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);
Thank you
Re: Is it OK to use QSharedPointer in QListView?
Yes, it should be possible. How does your code look like and what are the errors you are getting?
Re: Is it OK to use QSharedPointer in QListView?
It's working now, I just forgot to initialize the QListView with "new keyword" before passing it a model :-)