Results 1 to 3 of 3

Thread: setData()

  1. #1
    Join Date
    Mar 2008
    Posts
    29
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default setData()

    Hey,
    I am not sure how to use the setData() method in my custom model. It seems to be, that the data is changed well, but the view is not updated since i clicked with the mouse on some other widgets. I am not sure how to handle the emit dataChanged() OR reset() methods...
    Anyone who can help me ?

    Qt Code:
    1. bool SchulungsplanModel::setData(const QModelIndex &index, const QVariant &value, int role)
    2. {
    3. if (index.isValid() && role == StartKursRole)
    4. {
    5. int puVectorIndex = findKursByRowValue(index.row()).at(0);
    6. int kurseVectorIndex = findKursByRowValue(index.row()).at(1);
    7.  
    8. QDate myCurrentCellDate = whereInTheDateAmI(index.column() );
    9. QDate startKursDate = m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getStartKursDatum();
    10. QDate endKursDate = m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getEndKursDatum();
    11.  
    12. bool dateBetweenCourseDate = isTheDateBetween( myCurrentCellDate, startKursDate, endKursDate);
    13.  
    14. if (dateBetweenCourseDate == true)
    15. {
    16. qDebug() << "startKursDatum: value.toDate().toString(): " << value.toDate().toString("dd.MM.yyyy");
    17. m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].setStartKursDatum(value.toDate());
    18. qDebug() << "startKursDatum changed in:" << m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].getStartKursDatum().toString("dd.MM.yyyy");
    19. }
    20. emit dataChanged(index, index);
    21. //reset();
    22. return true;
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setData()

    Quote Originally Posted by starcontrol View Post
    m_spData.getPUs()[puVectorIndex].getPUKurse()[kurseVectorIndex].setStartKursDatum(value.toDate());
    Are you sure that getPU*() methods and [] operators don't return copies of your data?

    Quote Originally Posted by starcontrol View Post
    emit dataChanged(index, index);
    //reset();
    return true;
    This is OK.

    You can try Modeltest to see whether your model is OK.

  3. The following user says thank you to jacek for this useful post:

    starcontrol (2nd May 2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    29
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setData()

    oh yes, .... it returned copies instead of references - aua :-/

Similar Threads

  1. setData()
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2008, 12:51
  2. model/view call setdata() function help?
    By dolphins in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2007, 01:58
  3. model/view setData help
    By nategoofs in forum Qt Programming
    Replies: 16
    Last Post: 19th August 2007, 18:00
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.