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. Aliases not working when connecting ui file with logic in separate qml file
Qt 6.11 is out! See what's new in the release blog

Aliases not working when connecting ui file with logic in separate qml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 822 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.
  • H Offline
    H Offline
    Hitokage
    wrote on last edited by
    #1

    Hello,
    I want to integrate C++ with QML and implement some logic in a separate file using alias. For some reason I can't make that work. I am making a mobile app, using the QT Quick - Stack template and it kinda looks like the aliases are not working at all for me. I've tried to create a simple example to verify where's the problem and it's not working either. Here is the example:

    G.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.12
    
    GForm{ button.onClicked: Qt.quit()}
    

    GForm.ui.qml

    import QtQuick 2.4
    import QtQuick.Controls 2.12
    
    Item {
        width: 400
        height: 400
        property alias button: button
    
        Button {
            id: button
            x: 167
            y: 149
            text: qsTr("Button")
        }
    }
    

    main.qml

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        GForm{}
    }
    

    Qt Creator screenshot.
    The button in the example doesn't do anything. If I however do this:

    GForm.ui.qml

    ...
    Button {
            id: button
            x: 167
            onClicked: Qt.quit() //HERE
            y: 149
            text: qsTr("Button")
        }
    ...
    

    It works but with some warnings that Functions are not supported in a Qt Quick UI form

    Am I misunderstanding something? Do I have to enable or import something more?
    Any help is much appreciated! Have a nice day!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hitokage
      wrote on last edited by Hitokage
      #2

      I was able to fix it after all. The problem was that I assumed that when having ui.qml and .qml file, they were already connected (nameForm.ui.qml and name.qml). What needs to be done is to use the .qml file to display the elements and put the .ui.qml inside.
      Like this:

      main.qml

      import QtQuick 2.9
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          //*GForm{} WRONG*/
          G{}
      }
      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