Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt on BlackBerry and QNX
  4. Accessing QML object in C++

Accessing QML object in C++

Scheduled Pinned Locked Moved Qt on BlackBerry and QNX
7 Posts 4 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheechm
    wrote on 23 Jan 2013, 15:32 last edited by
    #1

    Hi there,

    In one of my classes I have a Q_INVOKABLE function:

    @QDeclarativeEngine engine;
    QDeclarativeComponent component(&engine,
    QUrl::fromLocalFile("app/native/assets/loadingZones.qml"));
    QObject *zonesInstance = component.create();
    qDebug() << component.errors();

    label = zonesInstance->findChildbb::cascades::Label*("sLb");
    QString labelText = "Test Change";

    qDebug() << label->text();
    label->setText(labelText);
    qDebug() << labelText;@

    The qml is pretty simple:

    @Label {
    id: searchingLabel
    objectName: "sLb"
    text: qsTr("Searching for..")
    verticalAlignment: VerticalAlignment.Center
    horizontalAlignment: HorizontalAlignment.Center
    textStyle.lineHeight: 4.5
    textStyle.fontSize: FontSize.Large
    }
    @

    @qDebug() << label->text(); -> ouputs "Searching for.."
    label->setText(labelText);
    qDebug() << label->text(); -> ouputs "Test Change"@

    However, there isn't any change on the screen. What am I doing wrong?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 Jan 2013, 19:50 last edited by
      #2

      Add debug in QML:
      @
      onTextChanged: {
      console.log("Changed to: " + text);
      }
      @

      To see whether property value is really changing. Maybe you forgot to emit textChanged() signal in your c++ method?

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cheechm
        wrote on 23 Jan 2013, 22:42 last edited by
        #3

        Changed the QML to:

        @ Label {
        id: searchingLabel
        objectName: "sLb"
        text: qsTr("Searching for..")
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        textStyle.lineHeight: 4.5
        textStyle.fontSize: FontSize.Large
        onTextChanged: {
        console.log("Changed to: " + text);
        }
        } @

        And it outputs
        @Debug: Changed to: Test Change@

        No clue why it doesn't change on screen?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 24 Jan 2013, 07:34 last edited by
          #4

          I don't know. The only thing I can think of is this signal emission (textChanged()). Without it the engine will not know to update the item.

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bomb3rman
            wrote on 24 Jan 2013, 13:34 last edited by
            #5

            Hm...could you invoke the signal manualy with:
            label->textChanged();
            After you change the text.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 24 Jan 2013, 13:54 last edited by
              #6

              I might be misunderstanding the issue, but it seems to me you need a full Q_PROPERTY (complete with a notification signal) instead of just an invokable method?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cheechm
                wrote on 24 Jan 2013, 17:15 last edited by
                #7

                Could you explain a little further please Andre?

                1 Reply Last reply
                0

                1/7

                23 Jan 2013, 15:32

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved