Results 1 to 2 of 2

Thread: Dynamic QML Property Binding

  1. #1
    Join Date
    Aug 2012
    Posts
    5

    Default Dynamic QML Property Binding

    Hi

    Some QObject derived Classes in my Application are created and destroyed dynamicly during runtime.
    Those Objects are "injected" into QML be using setContextProperty:

    Qt Code:
    1. SomeObject* someObjectInstance = new SomeObject();
    2. view.rootContext()->setContextProperty("someObjectInstance", someObjectInstance);
    To copy to clipboard, switch view to plain text mode 
    view is a QDeclarativeView here.


    Well, basically this works. But it takes a lot of time and sometimes the Application even crashes. It seems like all bindings of the Context are reevaluate when i add a new Context Property.

    So i think im doing something completely wrong here. Is there a way to achieve the desired dynamic binding, without all binding having to reevaluate? I searched the web and did read the Documentation, but didnt seem to find anything when it comes to more advanced interaction between QML and C++.

    What happens to the binding if a QObject that was exported using QDeclarativeContext::setContextProperty is destoyed? will the Binding still be there?
    Last edited by EMCEE; 29th August 2012 at 13:51.

  2. #2
    Join Date
    Aug 2012
    Posts
    5

    Default Re: Dynamic QML Property Binding

    I think i found that the bindings are not reevaluated if they are overwritten.

    So for now i have to create some pseudo ContextProperties at the start of my application:

    Qt Code:
    1. context->setContextProperty("someObjectInstance", NULL);
    2. context->setContextProperty("otherProperty", NULL);
    To copy to clipboard, switch view to plain text mode 

    and later if a Object gets instantiated, i just overwrite these:

    Qt Code:
    1. context->setContextProperty("someObjectInstance", someObjectInstance);
    2. context->setContextProperty("otherProperty", otherQObject);
    To copy to clipboard, switch view to plain text mode 

    It works...but its ugly...

    Is it even ok to overwrite a ContextProperty?

Similar Threads

  1. QML Property Binding update does not propagate
    By bluestreak in forum Qt Quick
    Replies: 0
    Last Post: 21st August 2012, 20:24
  2. Replies: 0
    Last Post: 17th October 2011, 14:07
  3. Replies: 1
    Last Post: 20th January 2011, 18:17
  4. Change Stylesheet Using Dynamic Property
    By stefanadelbert in forum Qt Programming
    Replies: 4
    Last Post: 26th August 2010, 08:48
  5. Dynamic property and stylesheets
    By aamer4yu in forum Qt Programming
    Replies: 10
    Last Post: 18th November 2009, 19:26

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.