Discussion Board

Results 1 to 3 of 3
  1. #1
    Nokia Developer Expert
    Join Date
    Jul 2011

    Accessing QML objects from C++


    I am trying to encapsulate QML - Cpp interface in a class, but it seems that I can not find the QObjects in the QML files. I tried this:

    Q_INVOKABLE void QMLCppBinder::changeText() {

    QDeclarativeContext *context = view.rootContext();

    QObject *change_text = context->findChild<QObject *>(QString("changeText"));

    if (change_text){
    change_text->setProperty("text", QString("changed text"));
    else {
    qDebug() << "changeText" << " not found";
    This function should respond to user clicking on a MouseArea by changing the text in the MouseArea.
    But no matter where I put the objectName: "changeText" in the respective QML file, it is not found. findChild() returns 0 every time.

    Any pointers what I am doing wrong or how to poke this problem; I have certainly tried a few variations already, but all in vain.

    br, _perza
    Last edited by _perza; 2011-09-15 at 06:01.

  2. #2
    Registered User
    Join Date
    May 2009

    Re: Accessing QML objects from C++

    May be you should consider using function QDeclarativeContext::contextProperty instead of QObject::findChild.

  3. #3
    Super Contributor
    Join Date
    Jun 2006

    Re: Accessing QML objects from C++

    check findQMLElement function, it will be helpful for you.
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

Similar Threads

  1. Accessing data from RPointerArray objects
    By avinash_ji in forum Symbian
    Replies: 2
    Last Post: 2009-11-20, 06:54
  2. Accessing objects from another Thread
    By Saxer in forum Symbian
    Replies: 1
    Last Post: 2008-08-24, 17:56
  3. Accessing data in RChunk objects...
    By profoundwhispers in forum Symbian
    Replies: 1
    Last Post: 2006-06-13, 15:56
  4. SSL Objects
    By ohko in forum Symbian
    Replies: 2
    Last Post: 2005-09-14, 22:55
  5. MMS and objects
    By rdx83 in forum Symbian
    Replies: 0
    Last Post: 2004-09-15, 15:19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts