Results 1 to 3 of 3

Thread: SectionScroller and QList<QObject*>

  1. #1
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default SectionScroller and QList<QObject*>

    Hi,

    I'd like to use QML SectionScroller with a QList<QObject*> based model.
    My ListView's section configuration is:
    Qt Code:
    1. section.criteria: ViewSection.FirstCharacter
    2. section.property: "form0"
    To copy to clipboard, switch view to plain text mode 

    Where form0 property is valid and displayed in the view

    When the SectionScroller is inserted to the QML code, I'm getting an error:

    Qt Code:
    1. .../com/nokia/meego/SectionScroller.qml:319: Error: cannot assign [undefined] to QString
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong? I'd prefer to avoid QAbstractListModel, as I think it'd be an overkill right there - the elements are like this:

    Qt Code:
    1. class IrregularVerb : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QString form0 READ getForm0 NOTIFY formChanged)
    5. Q_PROPERTY(QString form1 READ getForm1 NOTIFY formChanged)
    6. Q_PROPERTY(QString form2 READ getForm2 NOTIFY formChanged)
    7. // internal stuff there
    8. };
    To copy to clipboard, switch view to plain text mode 

    Thanks

  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: SectionScroller and QList<QObject*>

    Are you sure form0 is defined for every object in the model? Can you prepare 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
    Dec 2011
    Posts
    9
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: SectionScroller and QList<QObject*>

    Quote Originally Posted by wysota View Post
    Are you sure form0 is defined for every object in the model? Can you prepare a minimal compilable example reproducing the problem?
    Element:

    Qt Code:
    1. class IrregularVerb : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QString form0 READ getForm0 NOTIFY formChanged)
    5. Q_PROPERTY(QString form1 READ getForm1 NOTIFY formChanged)
    6. Q_PROPERTY(QString form2 READ getForm2 NOTIFY formChanged)
    7. public:
    8. QString forms[3];
    9. QString getForm0() const { return getForm(0); }
    10. QString getForm1() const { return getForm(1); }
    11. QString getForm2() const { return getForm(2); }
    12. IrregularVerb(QString a, QString b, QString c) { forms[0] = a; forms[1] = b; forms[2] = c; }
    13. protected:
    14. const QString& getForm(const int& ind) const { return forms[ind]; }
    15. signals:
    16. void formChanged();
    17. };
    To copy to clipboard, switch view to plain text mode 

    Container for elements:
    Qt Code:
    1. class german : public QList<QObject*>
    2. {
    3. public:
    4. german();
    5. };
    6.  
    7. german::german()
    8. {
    9. append(new IrregularVerb("anfangen", "fing an", "angefangen")); // and so on
    10. }
    To copy to clipboard, switch view to plain text mode 

    Class managing the containers:

    Qt Code:
    1. class IrregularListWrapper : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QList<QObject*> db READ getdb NOTIFY langChanged)
    5. Q_ENUMS(Language)
    6. public:
    7. enum Language
    8. {
    9. English = 0,
    10. German = 1
    11. };
    12.  
    13. IrregularListWrapper() : db(0) { setLang(German); }
    14. ~IrregularListWrapper() { delete db; }
    15. QList<QObject*> getdb() const { return *db; }
    16.  
    17. Q_INVOKABLE void changeLang(Language l) { delete db; setLang(l); }
    18.  
    19.  
    20. signals:
    21. void langChanged();
    22. protected:
    23. void setLang(Language);
    24. QList<QObject*> * db;
    25. };
    26.  
    27. void IrregularListWrapper::setLang(Language l)
    28. {
    29. switch (l)
    30. {
    31. case English:
    32. db = new english;
    33. langName = "English";
    34. break;
    35. case German:
    36. db = new german;
    37. langName = "German";
    38. break;
    39. }
    40. emit langChanged();
    41. }
    To copy to clipboard, switch view to plain text mode 

    ListView:

    Qt Code:
    1. ListView
    2. {
    3. id: irrview
    4. width: parent.width
    5. model: irregulars.db
    6. anchors.top: caption.bottom
    7. anchors.bottom: parent.bottom
    8. spacing: 5
    9. clip: true
    10. section.criteria: ViewSection.FirstCharacter
    11. section.property: "form0"
    12. section.delegate: Item {height: 10; width: parent.width; Text { text: section } }
    13. delegate: Rectangle
    14. {
    15. height: 60
    16. width: parent.width
    17. color: "#E0E1E2"
    18. Row
    19. {
    20. height: parent.height
    21. width: parent.width - 10
    22. anchors.horizontalCenter: parent.horizontalCenter
    23. property real columnWidth: (width - 10) / 3
    24. property int rad: 10
    25. spacing: 5
    26. Rectangle
    27. {
    28. height: parent.height
    29. width: parent.columnWidth
    30. radius: parent.rad
    31. Text
    32. {
    33. anchors.centerIn: parent
    34. text: modelData.form0
    35. }
    36. }
    37. Rectangle
    38. {
    39. height: parent.height
    40. width: parent.columnWidth
    41. radius: parent.rad
    42. Text
    43. {
    44. anchors.centerIn: parent
    45. text: modelData.form1
    46. font.pointSize: 24
    47. }
    48. }
    49. Rectangle
    50. {
    51. height: parent.height
    52. width: parent.columnWidth
    53. radius: parent.rad
    54. Text
    55. {
    56. anchors.centerIn: parent
    57. text: modelData.form2
    58. }
    59. }
    60. }
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 

    All the forms (form0, form1, form2) are displayed in teh ListView, and all the model elements are displayed.
    If there's too much code, let me know

Similar Threads

  1. how to confirm the value of one QList in other QList quickly?
    By weixj2003ld in forum Qt Programming
    Replies: 5
    Last Post: 8th June 2012, 21:48
  2. Qlist<QLabel *> in Qlist<QAction*>
    By Naahmi in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2011, 09:53
  3. QObject subclass in a QList
    By plan_rich in forum Newbie
    Replies: 3
    Last Post: 21st September 2010, 16:51
  4. Replies: 4
    Last Post: 20th August 2010, 14:54
  5. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 09:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.