Results 1 to 4 of 4

Thread: QStandardItemModel with QIdentityProxyModel

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QStandardItemModel with QIdentityProxyModel

    Hi , i have a problem with QStandardItemModel and QIdentityProxyModel.

    I've implemented a QIdentityProxyModel to be able to change the way of displaying the model. Here is the data() function of QIdentityProxyModel :

    Qt Code:
    1. QVariant data(const QModelIndex &index, int role) const
    2. {
    3. if (role == Qt::DisplayRole && index.column() == AlarmLogViewIndex_RecovTime){
    4. qDebug()<< sourceModel()->data(index);
    5. qint64 sinceEpoch = sourceModel()->data(index).toLongLong();
    6. const QDateTime dateTime = QDateTime::fromMSecsSinceEpoch(sinceEpoch);
    7.  
    8. return dateTime.toString(m_formatString);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    This works like a charm when source model is a QSqlTableModel. But i need to use the same QIdentityProxyModel for a QStandardItemModel. When i use standartItemModel as the source of QIdentityProxyModel , i get QVariant(Invalid) values from the above data() function (in qDebug output...) . I was suspicious about the way i created the StandardItemModel. But it works well without the QIdentityProxyModel .

    Here is how i implement the StandardItemModel,

    adding a row to the model:
    Qt Code:
    1. void TagChannelItemModel::addToTagModel(pEtiketDef_t tg)
    2. {
    3. int row = tagModel->rowCount();
    4.  
    5. QStandardItem* item = new QStandardItem(QString::number(tg.Id));
    6. tagModel->setItem(row, TgIndex_Id, item);
    7.  
    8. item = new QStandardItem(tg.Name);
    9. tagModel->setItem(row, TgIndex_Name, item);
    10.  
    11. item = new QStandardItem(QString::number(tg.PollFrequency));
    12. tagModel->setItem(row, TgIndex_PollFreq, item);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Should i do anything else for this item model to work with ProxyModel ?

    Thanks in advance...
    Last edited by yagabey; 6th December 2014 at 21:56.

Similar Threads

  1. Replies: 3
    Last Post: 22nd March 2014, 15:57
  2. Replies: 3
    Last Post: 12th July 2013, 21:27
  3. how to use QIdentityProxyModel?
    By ecanela in forum Qt Programming
    Replies: 4
    Last Post: 3rd August 2012, 20:29
  4. using QStandardItemModel
    By GrahamLabdon in forum Newbie
    Replies: 1
    Last Post: 6th March 2011, 09:13
  5. QStandardItemModel Help
    By frenk_castle in forum Newbie
    Replies: 1
    Last Post: 16th January 2010, 17:54

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
  •  
Qt is a trademark of The Qt Company.