Results 1 to 9 of 9

Thread: QListView drag error with qmetatype

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QListView drag error with qmetatype

    I made a QListView which has a source of QStandardItemModel. I set the view to have the following settings

    Qt Code:
    1. setMovement(QListView::Snap);
    2. setResizeMode(QListView::Adjust);
    3. setSpacing(5);
    4. setViewMode(QListView::IconMode);
    To copy to clipboard, switch view to plain text mode 

    My model's item is a QStandardItem and i added my "metatype registered value" at Qt::UserRole + 1. When I started draging the item in my view the whole things just crushes, but when i took my metatype registered value in my item it works fine. This will only happen when i drag those icons. I have accessed and displayed my custom data through the modelIndex and its fine no crushes.

    below is how i declare my metatype value

    Qt Code:
    1. struct s_SqlListInfo
    2. {
    3. QVariant queryName;
    4. QVariant dataBaseName;
    5. QList <QString> reqTableList;
    6. QString sqlStatement;
    7. };
    8.  
    9. // Qt MetaType Declaration
    10. Q_DECLARE_METATYPE(s_SqlListInfo)
    11.  
    12. //spot where i added my value to the item
    13.  
    14. QVariant myVal = hander->list().at(0); // hander->list() ,returns a QList of Qvariant with my custom data
    15. if (myVal .canConvert<s_SqlListInfo>())
    16. {
    17. s_SqlListInfo info = myVal .value<s_SqlListInfo>();
    18.  
    19.  
    20. item->setData(info.queryName.toString(),Qt::DisplayRole);
    21. item->setData(QIcon(":/ListIcon.png"),Qt::DecorationRole);
    22. item->setData(myVal ,Qt::UserRole+1); // spot where i added my custom data
    23. item->setData(info.sqlStatement,Qt::ToolTipRole);
    24. item->setFlags(item->flags()& ~Qt::ItemIsEditable);
    25.  
    26. m_userListModel->appendRow(item);
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QListView drag error with qmetatype

    Can you provide a minimal compilable example reproducing the problem?
    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
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView drag error with qmetatype

    here we go

    Qt Code:
    1. #include <QtGui>
    2.  
    3. struct myStruct
    4. {
    5. QVariant queryName;
    6. QVariant dataBaseName;
    7. QList <QString> reqTableList;
    8. QString sqlStatement;
    9. };
    10. Q_DECLARE_METATYPE(myStruct)
    11.  
    12. int main (int argc,char *argv[])
    13. {
    14. QApplication app(argc,argv);
    15. QListView *view = new QListView;
    16.  
    17. view->setViewMode(QListView::IconMode);
    18.  
    19.  
    20. for (int i=0; i < 5; ++i)
    21. {
    22. item->setData(QString("Item %1").arg(i),Qt::DisplayRole);
    23. // custom data
    24. myStruct st;
    25. v.setValue(st);
    26. item->setData(v);
    27.  
    28. model->appendRow(item);
    29. }
    30.  
    31. view->setModel(model);
    32. view->show();
    33.  
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QListView drag error with qmetatype

    It works fine for me on Qt 4.5.2.
    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.


  5. #5
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView drag error with qmetatype

    I am still @ 4.5.1 I did not realize they have 4.5.2 already....

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QListView drag error with qmetatype

    I don't think this is a matter of different releases.
    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.


  7. #7
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView drag error with qmetatype

    When you said it work.. did you try dragging an item somewher else?

  8. #8
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView drag error with qmetatype

    I think it's the Q_ASSERT_X thats doing it(crashing) . When it crash it gave an ASSERT Error on line 1951 in qvariant.cpp . I tried recompiling it on release mode and it work.

    Why would qvariant assert something legal , maybe a warning would be fine not QUIT.. or maybe i am using qvariant the wrong way..

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: QListView drag error with qmetatype

    Quote Originally Posted by baray98 View Post
    When you said it work.. did you try dragging an item somewher else?
    Somewhere else meaning where?
    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.


Similar Threads

  1. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13
  2. Replies: 0
    Last Post: 10th November 2006, 13:46

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.