Results 1 to 3 of 3

Thread: Is it OK to use QSharedPointer in QListView?

  1. #1
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question 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:
    Qt Code:
    1. class DicomImageModel : public QAbstractTableModel
    2. {
    3. Q_OBJECT
    4. public:
    5. DicomImageModel(QObject *parent = 0);
    6. int rowCount(const QModelIndex &parent = QModelIndex()) const ;
    7. int columnCount(const QModelIndex &parent = QModelIndex()) const;
    8. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    9.  
    10. void addImage(const XImageObjectPtr image);
    11. private:
    12. std::vector<XImageObjectPtr> m_dicomImages;
    13. };
    To copy to clipboard, switch view to plain text mode 

    and:

    Use of this model:
    Qt Code:
    1. DicomImageModel model;
    2. foreach (XObjectPtr obj, XContainer::instance()->findObjectsByClass(XObject::Image)) {
    3. XImageObjectPtr image = obj.dynamicCast<XImageObject>();
    4. xLogWarning(XLogRecord::Type_User, tr("ID: %1").arg(image->getId()));
    5. model.addImage(image);
    6. }
    7. m_listview->setModel(&model);
    8. m_mainWidget->layout()->addWidget(m_listview);
    To copy to clipboard, switch view to plain text mode 

    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default 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 :-)

Similar Threads

  1. Replies: 11
    Last Post: 20th November 2012, 22:18
  2. QSharedPointer / QWeakPointer in QML?
    By centipede in forum Qt Quick
    Replies: 1
    Last Post: 23rd May 2012, 09:25
  3. inserting to Qlist of QSharedPointer
    By jajdoo in forum Newbie
    Replies: 1
    Last Post: 11th August 2011, 00:20
  4. emitting QSharedPointer
    By babu198649 in forum Newbie
    Replies: 11
    Last Post: 26th July 2010, 08:51
  5. Problem with QSharedPointer
    By weaver4 in forum Newbie
    Replies: 2
    Last Post: 19th April 2010, 14:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.