Results 1 to 17 of 17

Thread: How to access any method of any qml item from c++ side

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: how to access a methot of any qml item from c++

    I'm trying to do the same thing and it does not work for me. My test code does not find the "append(jsobject)" method, in my case the append method is show as "append(QQmlV4Function*)" and the QQmlV4Function type is a private Qt type so I can't invoke the method. Can provide more details on how you implemented this? What arguments are you passing on Q_ARG(blah blah)? What version of Qt are you using? Thanks.

  2. #2
    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: how to access a methot of any qml item from c++

    Again: create the model in C++, export an instance of it to QML via setContextProperty.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: how to access a methot of any qml item from c++

    Quote Originally Posted by anda_skoa View Post
    Again: create the model in C++, export an instance of it to QML via setContextProperty.

    Cheers,
    _
    That's actually not an option for me or at least I can't think of a way to make it work for me. I'm working on an interface to a graphical programming abstraction layer for QML so the user will create QML GUIs and then manipulate their properties with the graphical programming interface. My problem is that I have to manipulate lists created in QML with roles and data that is only available at run time. I tried adding dynamic properties to objects but it seems they have to be declared with Q_PROPERTY at compile time to be usable with the setContextProperty method. I actually managed to manipulate lists using QQmlExpression but the QMetaMethod's invoke method approach seems more elegant to me.

  4. #4
    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: how to access a methot of any qml item from c++

    So the user uses your graphic abstraction for the UI but then types ListModels manually?
    Wouldn't it be better to allow the user to edit model data with some nice editor UI as well?

    Otherwise what do you gain over using the QtQuick designer?

    Cheers,
    _

  5. #5
    Join Date
    Oct 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: how to access a methot of any qml item from c++

    Quote Originally Posted by anda_skoa View Post
    So the user uses your graphic abstraction for the UI but then types ListModels manually?
    Wouldn't it be better to allow the user to edit model data with some nice editor UI as well?

    Otherwise what do you gain over using the QtQuick designer?

    Cheers,
    _
    Not exactly, the users will design the QML UI on the designer or by hand. All the logic will be done in a graphics based code simulation environment that will interact with the QML UI using the library that I'm putting together. They will have to create a ListModel manually and then manipulate the elements using the graphical blocks from the code simulation program. Then they can generate code from the simulation program, compile it and have a fully functioning application with minimal manual text coding.

  6. #6
    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: how to access a methot of any qml item from c++

    So do they add ListElement entries manually or just create a ListModel?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2015
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: how to access a methot of any qml item from c++

    Quote Originally Posted by anda_skoa View Post
    So do they add ListElement entries manually or just create a ListModel?

    Cheers,
    _
    They create the initial ListModel and ListElements in QML and then add, delete and modify the elements from the graphical code simulation environment.

  8. #8
    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: how to access a methot of any qml item from c++

    Ah, hmm.

    Without the need to add elements in QML code that would be easy: a custom model type would allow instantiation from QML and also provide complete control over its C++ API.

    Ok, so you'll need a ListModel subtype that has additional functions.
    Something like
    Qt Code:
    1. // MyListModel
    2. import QtQuick 2.0
    3.  
    4. ListModel {
    5. function appendFromJSON(string jsonString) {
    6. // get data from jsonString, call append()
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Then use MyListModel instead of ListModel.

    Cheers,
    _

    P.S.: be sure you and the users understand the inherent limitations of ListModel/ListElement, e.g. can't deal with translatable strings.
    This is usually only used for prototyping while real model data is not available or for very rare cases when data is fixed and does not contain user visible text.

Similar Threads

  1. How to call a static method of java from c++ side?
    By stereoMatching in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 31st December 2013, 15:54
  2. Replies: 0
    Last Post: 15th December 2011, 05:54
  3. Replies: 3
    Last Post: 15th April 2010, 13:26
  4. How to access myApp->method from a child
    By bnilsson in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2008, 13:22

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.