Results 1 to 5 of 5

Thread: Show complex cpp data model in QML

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2012
    Posts
    6
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Show complex cpp data model in QML

    i have tow c++ data model like this :
    post data model:
    Qt Code:
    1. class post_data_model : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit post_data_model(QObject *parent = 0);
    7.  
    8. Q_PROPERTY(QString key READ key WRITE set_key)
    9. Q_PROPERTY(QString text READ text WRITE set_text)
    10. Q_PROPERTY(QString raw_text READ raw_text WRITE set_raw_text)
    11. Q_PROPERTY(QVariant tags READ tags)
    12.  
    13. void set_key(QString key);
    14. void set_text(QString text);
    15. void set_raw_text(QString raw_text);
    16. void set_tags(QList <QObject *> tags);
    17.  
    18. QString key();
    19. QVariant tags();
    20. QString text();
    21. QString raw_text();
    22.  
    23. private:
    24. QString m_key;
    25. QList <QObject *> m_tags;
    26. QString m_text;
    27. QString m_raw_text;
    28. }
    To copy to clipboard, switch view to plain text mode 

    and,tag data model :
    Qt Code:
    1. class tags_model : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit tags_model(QObject *parent = 0);
    6.  
    7. Q_PROPERTY(QString key READ key WRITE set_key)
    8. Q_PROPERTY(QString name READ name WRITE set_name)
    9.  
    10. void set_key(QString key);
    11. void set_name(QString name);
    12.  
    13. QString key();
    14. QString name();
    15. private:
    16. QString m_key;
    17. QString m_name;
    To copy to clipboard, switch view to plain text mode 

    QML Code :
    Qt Code:
    1. import QtQuck 2.2
    2. import QtQuick.Window 2.1
    3. import QtQuick.Controls 1.2
    4.  
    5. Window {
    6. id:container_window
    7. visible: true
    8. width: 360
    9. height: 360
    10. color: "#E6E7E7"
    11. property bool get_profile_status :false
    12. onActiveChanged:
    13. {
    14. if (get_profile_status==false)
    15. {
    16. Posts_Action.get_posts_stream();
    17. get_profile_status=true
    18. }
    19.  
    20. }
    21.  
    22. ListView
    23. {
    24. id:posts_list_view
    25. height: 200
    26. width: 200
    27. spacing: 5
    28. clip: true
    29. delegate: posts_delegate
    30. }
    31.  
    32.  
    33. Component
    34. {
    35. id: posts_delegate
    36.  
    37. Item {
    38. height: 150
    39.  
    40. Text {
    41. id: post_content_txt
    42. width: 200
    43. wrapMode: Text.WordWrap
    44. anchors.topMargin: 10
    45. text: qsTr(modelData.text)
    46. }
    47.  
    48. //Tags : No idea
    49. //How Can show list of tags?
    50. }
    51. }
    52.  
    53. Item {
    54. id: exteras
    55. Connections
    56. {
    57. target:Posts_Action
    58. onParsfinished:
    59. {
    60. posts_list_view.model=Posts_Action.post_list();
    61. }
    62. onNetwork_error_occurred :
    63. {
    64. console.log("ERROR: " + error_message);
    65. }
    66. }
    67. }
    To copy to clipboard, switch view to plain text mode 

    i can use the property of post model in QML such as the key and text but the point is that i cannot have access to the list of tags...
    now,how can i show the list of post tags in QML?
    Last edited by ms2222; 18th February 2015 at 09:45.

Similar Threads

  1. Using model indices in complex model item relationships
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 29th June 2011, 14:30
  2. Printing complex page with changing data
    By marcvanriet in forum Qt Programming
    Replies: 4
    Last Post: 22nd December 2010, 01:15
  3. Replies: 1
    Last Post: 23rd November 2008, 14:11
  4. Something fishy about Model, data doesn't show up!
    By zlosynus in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2008, 15:07
  5. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 20:59

Tags for this Thread

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.