Results 1 to 4 of 4

Thread: Model display problem

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Model display problem

    Hey!
    I have implemented a model...it worked just fine without any problem...
    UNTIL one moment
    Here is the snippet of data() method that specify how the data should be displayed by the view:
    Qt Code:
    1. if(row >= 0 && row < rowCount()) {
    2. if(role == Qt::DisplayRole) {
    3. const QVcaCanMsg &msg = msgList.at(row);
    4. switch(col) {
    5. case 0 :
    6. {
    7. ret = QVariant((unsigned)msg.id());
    8. }
    9. break;
    10. case 1:
    11. {
    12. ret = msg.flags();
    13. }
    14. break;
    15. case 2 :
    16. {
    17. QDateTime ts = QDateTime::fromTime_t(msg.timestamp().tv_sec);
    18. //ts = ts.addMSecs(1000 * msg.timestamp().tv_usec);
    19. ret = ts;
    20. }
    21. break;
    22. case 3 :
    23. {
    24. ret = msg.length();
    25. }
    26. break;
    27. case 4 :
    28. {
    29. ret = QString(QByteArray((const char*)msg.data(), msg.length()).toHex()).toUpper();
    30. }
    31. break;
    32. default :
    33. break;
    34. }
    35. }
    36. }
    37. return ret;
    To copy to clipboard, switch view to plain text mode 
    I have decided instead of displaying int numbers of id(unsigned long) and flags(integer) (returned by id() and flags() methods) to display them hexadecimally...
    and thats where the problem occured..
    I have changed the previous code to:
    Qt Code:
    1. case 0 :
    2. {
    3. QString str;
    4. ret = str.setNum(msg.id(), 16).toUpper();
    5. }
    6. break;
    7. case 1:
    8. {
    9. QString str;
    10. ret = str.setNum(msg.flags(), 16).toUpper();
    11. }
    To copy to clipboard, switch view to plain text mode 
    now the items added to the model DOES NOT GET DISPLAYED AT ALL.
    When I leave the original solution displaying ulong/int numbers everything works just fine...
    Anyone has an idea what am I doing wrong ?
    Thanks

    ps: when I print with the QDebug the value of "str" it gets printed in a correct way - as hexadecimal number of given id/flags
    Last edited by gyre; 31st December 2007 at 06:19. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Model display problem

    what data type should this function return, a QVariant?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model display problem

    You already did it ok in the first example. I don't understand why you messed it up in the second. It should be:
    Qt Code:
    1. case 0 :
    2. {
    3. QString str;
    4. ret = QVariantr(str.setNum(msg.id(), 16).toUpper());
    5. }
    6. break;
    7. case 1:
    8. {
    9. QString str;
    10. ret = QVariant(str.setNum(msg.flags(), 16).toUpper());
    11. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Model display problem

    Let me inform that the problem was already solved. He was using a proxy model which filtered out everything but integers, thus no hexadecimal numbers were displayed.

    PS. gyre, could you pay more attention to the way you jump between this forum and #qt, please? You always ask your questions in both places. People are here to help you for free, for their own willingness. Do not waste their time by leaving here open questions that were already solved elsewhere. Don't act like these two communities didn't know about each other. It feels funny to read on #qt that "a friend of yours advised to do this and that" when it was in fact advised by me myself or someone else on this forum.
    J-P Nurmi

Similar Threads

  1. tableview model view problem
    By skuda in forum Qt Programming
    Replies: 5
    Last Post: 3rd December 2007, 14:02
  2. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  3. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45
  4. Relational Table Model Problem
    By aekilic in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2007, 14:57
  5. Replies: 3
    Last Post: 12th April 2006, 08:20

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.