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. Signals and Handlers not working!

Signals and Handlers not working!

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

    Hello,

    The example below is taken from the http://doc.qt.io/qt-5/qtqml-syntax-signals.html.
    There are two qml files. The signal is in SquareButton.qml and the handler is in the myapplication.qml. When I ran it, it does not do anything when I click the mouse area.
    Can anybody please help me?

    // SquareButton.qml
    Rectangle {
    id: root

    signal activated(real xPosition, real yPosition)
    
    width: 100; height: 100
    
    MouseArea {
        anchors.fill: parent
        onPressed: root.activated(mouse.x, mouse.y)
    }
    

    }

    // myapplication.qml
    SquareButton {
    onActivated: console.log("Activated at " + xPosition + "," + yPosition)
    }

    ? 1 Reply Last reply
    0
    • JticaJ Jtica

      Hello,

      The example below is taken from the http://doc.qt.io/qt-5/qtqml-syntax-signals.html.
      There are two qml files. The signal is in SquareButton.qml and the handler is in the myapplication.qml. When I ran it, it does not do anything when I click the mouse area.
      Can anybody please help me?

      // SquareButton.qml
      Rectangle {
      id: root

      signal activated(real xPosition, real yPosition)
      
      width: 100; height: 100
      
      MouseArea {
          anchors.fill: parent
          onPressed: root.activated(mouse.x, mouse.y)
      }
      

      }

      // myapplication.qml
      SquareButton {
      onActivated: console.log("Activated at " + xPosition + "," + yPosition)
      }

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Works for me. Do you get any error messages?

      import QtQuick 2.7
      
      Rectangle {
          id: root
      
          signal activated(real xPosition, real yPosition)
      
          width: 100; height: 100
          color: "blue"
      
          MouseArea {
              anchors.fill: parent
              onPressed: {
                  root.activated(mouse.x, mouse.y)
              }
          }
      }
      
      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.0
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          SquareButton {
              onActivated: console.log("Activated at " + xPosition + "," + yPosition)
          }
      }
      
      JticaJ 1 Reply Last reply
      1
      • ? A Former User

        Hi! Works for me. Do you get any error messages?

        import QtQuick 2.7
        
        Rectangle {
            id: root
        
            signal activated(real xPosition, real yPosition)
        
            width: 100; height: 100
            color: "blue"
        
            MouseArea {
                anchors.fill: parent
                onPressed: {
                    root.activated(mouse.x, mouse.y)
                }
            }
        }
        
        import QtQuick 2.7
        import QtQuick.Controls 2.0
        import QtQuick.Layouts 1.0
        
        ApplicationWindow {
            visible: true
            width: 640
            height: 480
            title: qsTr("Hello World")
        
            SquareButton {
                onActivated: console.log("Activated at " + xPosition + "," + yPosition)
            }
        }
        
        JticaJ Offline
        JticaJ Offline
        Jtica
        wrote on last edited by
        #3

        @Wieland
        Hello,

        I know it is different from the example, but hey it works!
        Thanks!

        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