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. Can't make .ui.qml work with .qml

Can't make .ui.qml work with .qml

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

    Hi, i'm using this simple component to try the feature of separating logic from interface declaration:

    TestComponentForm.ui.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Item {
        width: 1024
        height: 768
    
        property alias button: button
    
        Button {
            id: button
            x: 64
            y: 64
            text: qsTr("Button")
        }
    }
    

    TestComponent.qml

    import QtQuick 2.15
    
    TestComponentForm {
        button.onClicked: console.log("log from TestComponent");
    }
    

    But it doesn't work, nothing is printed in the log.

    I tried changing the TestComponent.ui.qml to TestComponent.qml and put the js function directly inside it:
    TestComponentForm.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Item {
        width: 1024
        height: 768
    
        property alias button: button
    
        Button {
            id: button
            x: 64
            y: 64
            text: qsTr("Button")
            onClicked: {
                console.log("log from TestComponentForm");
            }
        }
    }
    

    And it does work, but then, the logic isn't separated anymore ^^

    There must be something I'm missing. I'm trying to make a simple example like this work before refactoring the application I'm working on. But I can't. The two components were generated with Qt Design Studio when doing Add New... > Qt Quick UI Form. So I thought it would work from the get go but there must be something I'm missing.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t.vanbesien
      wrote on last edited by
      #2

      Found the answer, I was loading the .ui.qml file instead of the .qml file in my application... Haha.

      1 Reply Last reply
      0
      • T t.vanbesien has marked this topic as solved on

      • Login

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