Results 1 to 6 of 6

Thread: How to retrive data saved using Setdata?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default How to retrive data saved using Setdata?

    I have used QStandardItem::SetData to save data for each tree item, code is below:
    m_htHashItem->setData(QVariant(QVariant::UserType, m_pCurrMapData), MyClassRole);

    Now I need to retrieve it back on item click event
    MAP_DATA* p = static_cast< MAP_DATA *> (index.data(MyClassRole).value());

    but I am getting error:
    error: C2783: 'T QVariant::value(void) const' : could not deduce template argument for 'T'

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: How to retrive data saved using Setdata?

    Something like:
    Qt Code:
    1. struct MAP_DATA { };
    2. Q_DECLARE_METATYPE(MAP_DATA*)
    3.  
    4. // and assuming
    5. MAP_DATA *m_pCurrMapData;
    6.  
    7. // Elsewhere
    8. m_htHashItem->setData(QVariant(m_pCurrMapData), MyClassRole);
    9.  
    10. MAP_DATA* p = index.data(MyClassRole).value<MAP_DATA*>();
    To copy to clipboard, switch view to plain text mode 
    follows from the examples in the QVariant::value() docs

  3. #3
    Join Date
    Mar 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to retrive data saved using Setdata?

    Thanks for reply...not getting any error but getting NULL / 0 while getting value back.

    struct MAP_DATA { };

    enum MyRoles {
    MyClassRole = Qt::UserRole + 1
    };

    Q_DECLARE_METATYPE(MAP_DATA*)

    //set address of a linked list node
    m_htHashItem->setData(QVariant(QVariant::UserType, m_pCurrMapData), MyClassRole);

    //gettting same node
    MAP_DATA* pFileData = index.data(MyClassRole).value<MAP_DATA*>();

    But I am getting ZERO for pFileData everytime. Please let me know where am I wrong?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to retrive data saved using Setdata?

    Compare your setData() call with that ChrisW67 provided.
    Notice the difference.
    Fix.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: How to retrive data saved using Setdata?

    If I use SetData described by ChrisW67 then I am getting error in QT 5:
    error: C2248: 'QVariant::QVariant' : cannot access private member declared in class 'QVariant'

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to retrive data saved using Setdata?

    Try
    Qt Code:
    1. m_htHashItem->setData(QVariant::fromValue(m_pCurrMapData), MyClassRole);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 18th July 2013, 04:12
  2. Retrive values using qt
    By jeyanthinatarajan in forum Newbie
    Replies: 1
    Last Post: 5th July 2012, 08:31
  3. Replies: 1
    Last Post: 19th March 2009, 09:20
  4. Replies: 2
    Last Post: 15th February 2008, 18:54
  5. How I can retrive information abt file.
    By safknw in forum General Programming
    Replies: 3
    Last Post: 2nd December 2006, 13:35

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.