Results 1 to 11 of 11

Thread: Run time generated property set in C++ exposed to QML

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Run time generated property set in C++ exposed to QML

    Quote Originally Posted by don@thegagnes.com View Post
    As far as setting an id from the C++ side I was just trying to figure out how to use your example. The objects are all created in C++ and then pushed into a QML context. Given that, using an id won't work.
    You surely have a QML declaration somewhere which refers to a particular parameter (and you can do that via id), otherwise your QML code wouldn't know how to "call" a particular parameter as it might not exist.

    If I use a list model I won't be able to do something like this in QML will I?

    TextInput {
    text: parameters.PROP_1.value
    }
    If you put that in a delegate referencing a particular model entry then it would be simpler:

    javascript Code:
    1. ListView {
    2. id: view
    3. model: myModel
    4. // ...
    5.  
    6. Row {
    7. width: view.width
    8. Text { text: model.name }
    9. Slider {
    10. minimumValue: model.minimum
    11. maximumValue: model.maximum
    12. value: model.value
    13. onValueChanged: model.value = value
    14. }
    15. Text { text: model.value }
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    You could even have different types of parameters and construct a proper delegate depending on the type (e.g. putting a slider for numeric parameters and text field for textual ones).
    Last edited by wysota; 7th December 2014 at 22:26.
    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.


  2. #2
    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: Run time generated property set in C++ exposed to QML

    What you could try is a map

    Qt Code:
    1. class Properties : public QObject
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QVariantMap facts .... )
    5. };
    To copy to clipboard, switch view to plain text mode 
    where the key is the property name and the value is a Fact object

    Or exposing the map directly as a context property (if it does not change during runtime).

    Cheers,
    _

  3. #3
    Join Date
    Aug 2014
    Posts
    16
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Run time generated property set in C++ exposed to QML

    QVariantMap - That look like exactly what I need. Thank you very much.

Similar Threads

  1. Replies: 1
    Last Post: 24th November 2014, 08:28
  2. qtablewidget exposed lines
    By tuli in forum Newbie
    Replies: 1
    Last Post: 25th August 2014, 12:47
  3. Accessing C++ Element exposed for QML in C++
    By Rocken in forum Qt Quick
    Replies: 1
    Last Post: 22nd February 2012, 13:12
  4. Know Number of Property Exposed by the Widget
    By Ashutosh2k1 in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2011, 12:12

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.