Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML alias not working
Qt 6.11 is out! See what's new in the release blog

QML alias not working

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.1k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Dolphin
    wrote on last edited by
    #1

    Anyone any ideas why this code is not working? I have a loader in main which is happily loading files the c++ spits out to it but a slightly different mechanics is required for the username/password and I thought an alias would be simpler than a signal/slot. The loader (Main.qml) has an alias which I am trying to use to go from the username to the password (Loggon_username.qml)

    Main.qml

    @
    import QtQuick 2.0

    Rectangle
    {
    id: window
    property alias mainLoader: loader

    Component.onCompleted:
    {
        loader.forceActiveFocus()
    }
    
    Rectangle
    {
        id: promptsContainer
        width: parent.width
        height: prompts.height * 1.25
        color: "#2A51A3"
        anchors.top: parent.top
    
        Text
        {
            id: prompts //text showing what voice is saying
            anchors.centerIn: parent
            color: "orange"
            font.pointSize: 20 //coreMenu.promptsFontPointSize
            width: parent.width * 0.9
            wrapMode: Text.WordWrap
            clip: true
        }
    }
    
    Loader
    {
        id: loader
        height: window.height - promptsContainer.height
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        visible: source != ""
        source: "Loggon_password.qml"
        onSourceChanged: console.log(loader.source);
     }
    
     Keys.onPressed:
     {
        QMLManager.handleKey(event.key)
        loader.source =  QMLManager.getLoaderSource()
        console.log(loader.source)
     }
    

    }
    @

    Loggon_username.qml
    @import QtQuick 2.0

    Rectangle
    {
    anchors.fill: parent;

    Component.onCompleted:
    {
    
      // promptsBar.text = qsTr("Please enter your MTM username");
    }
    TextEntry
    {
        title: QMLManager.getTitle();
        onTextEntered:
        {
            QMLManager.setUsername(text);
            Main.mainLoader.setSource("Loggon_password.qml")
    
           // Main.mainLoader.source = "Help.qml"
        }
    }
    

    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      "Main" is outside of scope in your Loggon_username. It won't work.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dolphin
        wrote on last edited by
        #3

        What do you mean by out of scope? The doc says this should work if the qml files are in same directory :-)

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          "Main" would need to be defined somewhere in Loggon_username.qml for it to be visible inside. Or maybe I misunderstood the situation.

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Dolphin
            wrote on last edited by
            #5
            • if I import "Main.qml" the file will not load at all (which means it thinks there is a syntax error I think)
            • if main.qml file does not start with a capital when you type main.mainLoader it does not recognise it as a property
            • if Main.qml starts with 'M', when you are in the username file typing "Main." the text changes colour and you get a list of properties including the mainLoader

            ????

            I have tried this in a small test app and I get the same results

            1 Reply Last reply
            0

            • Login

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