×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    445

    C++/Qml communication and pageStack

    Hi,

    I am using PageStackedWindow on Harmattan. Pages are dynamically loaded from qml files.
    Now, I want to call a method from C++ within a loaded page, for instance function "dummyfnc":
    Code:
    import QtQuick 1.0
    import Qt 4.7
    import com.nokia.meego 1.0 
    Page {
    id: page1
    function dummyfnc() {
    // do something here
    }
    }
    I tried something like this, but it does not work:
    Code:
    QObject *object = (QObject*)m_qmlView.rootObject()->findChild<QObject*>("page1");
    // or
    QObject *object = (QObject*)m_qmlView.rootObject()->findChild<QDeclarativeItem*>("pageStack")->findChild<QDeclarativeItem*>("page1");
    
    QMetaObject::invokeMethod(object, "dummyfnc");
    How can I correctly invoke the method?
    Regards,

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    16

    Re: C++/Qml communication and pageStack

    Hi,

    Here is the sample example using signal slots concept for invoking the QML functions. Hope this meets your requirement.

    http://www.developer.nokia.com/Commu...o_QML_function

    Best Regards
    Sapur

  3. #3
    Regular Contributor
    Join Date
    Apr 2008
    Posts
    445

    Re: C++/Qml communication and pageStack

    Thanks, but my problem is not the connection in general, but the connection to a page which is dynamically added to the page stack. As a workaround I am now using a cascade of signals and slots but that's not very convenient. It would be much nicer if I could directly get a pointer to the page from my C++ code.

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: C++/Qml communication and pageStack

    Hi,
    QML IDs are not the same thing than QObject name.
    Set objectName property in your page1 and it will start to work.

    Reference:
    http://doc.qt.nokia.com/4.7-snapshot/qml-qtobject.html

Similar Threads

  1. PageStack transition animation
    By HellStranger in forum Nokia N9
    Replies: 8
    Last Post: 2011-12-02, 12:10
  2. How to change toolbar buttons in every pageStack page
    By shintu in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-11-06, 16:11
  3. Problem with PageStack - too much memory usage
    By rogeriopaladino in forum [Archived] Qt Quick
    Replies: 4
    Last Post: 2011-10-25, 22:29

Posting Permissions

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