Results 1 to 4 of 4

Thread: Issue with c++ model

  1. #1
    Join Date
    Oct 2011
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Issue with c++ model

    I have class:
    Qt Code:
    1. class diagSys : public QObject
    2. {
    3. Q_OBJECT
    4. ...
    5. Q_PROPERTY(QList<QObject *> periphList READ periphList NOTIFY sysConfigChanged)
    6. ...
    To copy to clipboard, switch view to plain text mode 

    periphList is list of objects:
    Qt Code:
    1. class BriefBlockInfoObject : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. Q_PROPERTY(char address READ address WRITE setAddress /*NOTIFY typeChanged*/)
    6. Q_PROPERTY(int id READ id WRITE setId /*NOTIFY textChanged*/)
    7. Q_PROPERTY(QString name READ name WRITE setName /*NOTIFY textChanged*/)
    8. ...
    To copy to clipboard, switch view to plain text mode 

    I wanna use periphList as model in qml. I export diagSys object:
    Qt Code:
    1. view->rootContext()->setContextProperty(QLatin1String("DIAG"),
    2. &diag);
    To copy to clipboard, switch view to plain text mode 

    From qml I use this:
    Qt Code:
    1. Repeater {
    2. ...
    3. model: DIAG.dispList
    4. ...
    To copy to clipboard, switch view to plain text mode 
    But It causes an error "ReferenceError: Can't find variable: name/address/id"

    But if I export like this:
    Qt Code:
    1. view->rootContext()->setContextProperty("dispModel",
    2. QVariant::fromValue(diag.dispList()));
    To copy to clipboard, switch view to plain text mode 
    and use as model dispModel:
    Qt Code:
    1. Repeater {
    2. ...
    3. model: dispModel
    4. ...
    To copy to clipboard, switch view to plain text mode 
    it perfectly works.

    How can I use as model property value of object, not object itself?

  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: Issue with c++ model

    Either declare the property as QVariant type (which will effectively make it equivalent to your second attempt) or do it the proper way and declare the property as QQmlListProperty type. This needs more work to be implemented properly but will give you full capabilities of a list property (e.g. possibility to add/remove entries from within QML).
    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
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Issue with c++ model

    I would also expect this to work.
    Your QML snippet uses a different property name than your C++, is this a typo?

    Cheers,
    _

  4. #4
    Join Date
    Oct 2011
    Posts
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Issue with c++ model

    The problem is solved. Just need to use modelData.name/modelData.address/modelData.id.

Similar Threads

  1. Replies: 1
    Last Post: 29th August 2013, 05:41
  2. Replies: 6
    Last Post: 2nd March 2013, 05:56
  3. QTableView massive model data updates issue
    By cyberbob in forum Newbie
    Replies: 3
    Last Post: 7th December 2010, 23:09
  4. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 11:03

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.