Results 1 to 6 of 6

Thread: interacting C++ QML

  1. #1
    Join Date
    Mar 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X

    Default interacting C++ QML

    hello,
    i would like understand qt, so i post here.

    rmq: QT : 5.7


    if i setProperty class in my qml.
    in this class, i have method Q_INVOKABLE what we return a pointeur in class.

    like this with no var in my qml:

    if (toto.test()!=NULL)
    toto.test().x() //method Q_INVOKABLE x()

    work but , the qml want manage the cobject returned by test()

    if i quit the qml page.
    qt would like delete the object returned by test() why??

    i would like juste interacting C++ and QML.

    what is the best method for use this? (no manage memory who i return in my q_INVOKABLE function)


    thank's for your reply
    Last edited by kickoune; 22nd September 2016 at 15:24.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: interacting C++ QML

    You can use QQmlEngine::setObjectOwnership() with QQmlEngine::CppOwnership on a given object to specify it should be owned by C++ side.
    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
    Mar 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: interacting C++ QML

    thank's to your reply

    Objects not-created by QML have CppOwnership by default.
    The exception to this are objects returned from C++ method calls; their ownership will be set to JavaScriptOwnership. This applies only to explicit invocations of Q_INVOKABLE methods or slots, but not to property getter invocations.
    Calling setObjectOwnership() overrides the default ownership heuristic used by QML.

    getter invocations = Q_PROPERTY() ?

    after Q_INVOKABLE Method in QML, i need to invok a method setObjectOwnership?

    it's bad way?


    Added after 45 minutes:


    if i just connect signal, qml manage this object.... i don't want this....

    getObj().signal.connect(fctQml)


    Added after 47 minutes:


    i have pass my pointer to setProperty, qt no manage memory, i think.

    but in slot function QML, sometimes variable who is setProperty in main() is no visible. why???
    Last edited by kickoune; 23rd September 2016 at 10:44.

  4. #4
    Join Date
    Mar 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: interacting C++ QML

    solved: i must use Connection ==> it's work.

  5. #5
    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: interacting C++ QML

    Quote Originally Posted by kickoune View Post
    Objects not-created by QML have CppOwnership by default.
    The exception to this are objects returned from C++ method calls; their ownership will be set to JavaScriptOwnership. [B]This applies only to explicit invocations of Q_INVOKABLE methods or slots, but not to property getter invocations.
    Instances of QObject derived classes returned from Q_INVOKABLE methods or slots are assumed to be owned by C++ if they have a parent and assumed to be owned by QML if they do not.
    Explicitly setting ownership takes precedence of course.

    A property getter is never invoked by the QML engine, so there is never any need to use either assumption.
    Property values are always owned by the object exposing the property.

    Quote Originally Posted by kickoune View Post
    after Q_INVOKABLE Method in QML, i need to invok a method setObjectOwnership?
    Yes, if you want a different behavior than the one based on parent check.

    Quote Originally Posted by kickoune View Post
    it's bad way?
    No, why would that be a bad way?

    Quote Originally Posted by kickoune View Post
    but in slot function QML, sometimes variable who is setProperty in main() is no visible. why???
    What?

    Cheers,
    _

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: interacting C++ QML

    but in slot function QML, sometimes variable who is setProperty in main() is no visible. why???
    You need to set context properties before you load the QML document.
    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.


Similar Threads

  1. Replies: 5
    Last Post: 23rd January 2012, 22:05
  2. QT implement for interacting Web Widget
    By ravikumar in forum Qt Programming
    Replies: 0
    Last Post: 22nd January 2012, 09:43
  3. interacting with qGraphicsItem
    By dubstar_04 in forum Newbie
    Replies: 1
    Last Post: 27th April 2011, 08:22
  4. Interacting QGraphicsItems together
    By sean.reynolds in forum Qt Programming
    Replies: 2
    Last Post: 16th April 2011, 09:35
  5. Interacting with an API
    By srohit24 in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2009, 14:17

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.