Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Using Loader Objects to Access C++ Methods

    General and Desktop
    2
    2
    976
    Loading More Posts
    • 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.
    • T
      Tjsail33 last edited by

      Is it possible to have QML files I load into a Loader object access C++ methods that the parent of the Loader has access to?

      @
      //Gives access to the main qml file
      this->ui->declarativeView->rootContext()->setContextProperty("appDelegate",this);
      @

      @
      //The Loader View that I would like to be able to use this method
      //Loader is a child of a Rectangle, which is the root object
      Loader {
      source: "MainNode.qml"
      anchors.centerIn: parent
      }
      @

      @
      //What I would like to do with the method in MainNode.qml
      //MouseArea is a child of a Rectangle, which is the root of the file.
      MouseArea {
      anchors.fill: parent
      onDoubleClicked: {
      parent.width: appDelegate.getScreenWidth();
      }
      }
      @

      How would I go about implementing this interaction?

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Is it not working when you just run what you wrote here?

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • First post
          Last post