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. Not able to handle Signals
Forum Updated to NodeBB v4.3 + New Features

Not able to handle Signals

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

    Hello all,
    I am newbie to Qt and trying to load different pages with loader. But, am getting following errors while running

    qrc:/ScreenPage.qml:10:5: QML Connections: Detected function "onSampleButtonPressed" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.

    qrc:/HomeScreen.qml:28: TypeError: Property 'sampleButtonPressed' of object [object Object] is not a function

    I think, i am handling the signals and its handlers properly. But, dont know where am doing wrong

    My code looks like this
    main.qml
    Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    id: rootWindowID

    ScreenPage {
        id:applicationWrapper
        anchors.centerIn: parent
    }
    

    }

    ScreenPage.qml
    Item {
    id:screenpage
    width: 640
    height: 480

    Connections {
        target: ScreenConfiguration
    
        function onSampleButtonPressed(pressed) {
            if(pressed === ScreenConfiguration.Pagenumbers.Page1)
            {
                //pageLoader.source = page1Component
                console.log("Page1")
            }
            else if(pressed === ScreenConfiguration.Pagenumbers.Page2)
            {
                //pageLoader.source = page2Component
                console.log("Page2")
            }
        }
    }
    
    /*Home Screen Component*/
    Component{
       id:homeScreenComponent
    
       //QML filenames should always start with Capital letters
        HomeScreen{  }
    }
    
    Loader{
        id:pageLoader
        anchors.fill: screenpage
        sourceComponent: homeScreenComponent // default and start page
    }
    

    }

    HomeScreen.qml
    Item {
    id: homescreenId
    width: 640
    height: 480

    Text {
        id: txtid1
        text: qsTr("Home Screen")
        width: parent.width
        height: 50
        anchors.left: parent.left
        font.pixelSize: 20
    }
    
    Button {
        id: buttonId1
        text: "Button1"
        width: 100
        height: 50
        anchors.top: txtid1.bottom
    
        onClicked: {
            console.log("Button1 Clicked")
            ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page1)
        }
    }
    
    Button {
        id: buttonId2
        text: "Button2"
        width: 100
        height: 50
        anchors.top: txtid1.bottom
        anchors.left: buttonId1.right
    
        onClicked: {
            console.log("Button2 Clicked")
            ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page2)
        }
    }
    

    }

    ScreenConfiguration.qml
    QtObject {

    signal sampleButtonPressed(int pressed)
    
    enum Pagenumbers {
        None = 0,
        Page1,
        Page2
    }
    

    }

    ODБOïO 1 Reply Last reply
    0
    • P Praveen.Illa

      Hello all,
      I am newbie to Qt and trying to load different pages with loader. But, am getting following errors while running

      qrc:/ScreenPage.qml:10:5: QML Connections: Detected function "onSampleButtonPressed" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.

      qrc:/HomeScreen.qml:28: TypeError: Property 'sampleButtonPressed' of object [object Object] is not a function

      I think, i am handling the signals and its handlers properly. But, dont know where am doing wrong

      My code looks like this
      main.qml
      Window {
      width: 640
      height: 480
      visible: true
      title: qsTr("Hello World")
      id: rootWindowID

      ScreenPage {
          id:applicationWrapper
          anchors.centerIn: parent
      }
      

      }

      ScreenPage.qml
      Item {
      id:screenpage
      width: 640
      height: 480

      Connections {
          target: ScreenConfiguration
      
          function onSampleButtonPressed(pressed) {
              if(pressed === ScreenConfiguration.Pagenumbers.Page1)
              {
                  //pageLoader.source = page1Component
                  console.log("Page1")
              }
              else if(pressed === ScreenConfiguration.Pagenumbers.Page2)
              {
                  //pageLoader.source = page2Component
                  console.log("Page2")
              }
          }
      }
      
      /*Home Screen Component*/
      Component{
         id:homeScreenComponent
      
         //QML filenames should always start with Capital letters
          HomeScreen{  }
      }
      
      Loader{
          id:pageLoader
          anchors.fill: screenpage
          sourceComponent: homeScreenComponent // default and start page
      }
      

      }

      HomeScreen.qml
      Item {
      id: homescreenId
      width: 640
      height: 480

      Text {
          id: txtid1
          text: qsTr("Home Screen")
          width: parent.width
          height: 50
          anchors.left: parent.left
          font.pixelSize: 20
      }
      
      Button {
          id: buttonId1
          text: "Button1"
          width: 100
          height: 50
          anchors.top: txtid1.bottom
      
          onClicked: {
              console.log("Button1 Clicked")
              ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page1)
          }
      }
      
      Button {
          id: buttonId2
          text: "Button2"
          width: 100
          height: 50
          anchors.top: txtid1.bottom
          anchors.left: buttonId1.right
      
          onClicked: {
              console.log("Button2 Clicked")
              ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page2)
          }
      }
      

      }

      ScreenConfiguration.qml
      QtObject {

      signal sampleButtonPressed(int pressed)
      
      enum Pagenumbers {
          None = 0,
          Page1,
          Page2
      }
      

      }

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Praveen-Illa said in Not able to handle Signals:

      qrc:/ScreenPage.qml:10:5: QML Connections: Detected function "onSampleButtonPressed" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.

      that is because of this

      Connections {
          target: ScreenConfiguration  //<<  target should be an object
      

      example :

      ScreenConfiguration { id: myConfig} // create an object 
      Connections {
          target: myConfig
      

      then HomeScreen.qml:28: TypeError: Property 'sampleButtonPressed' of object [object Object] is not a function
      same thing; you need an instance/object to access the signals/attributes

      onClicked: {
                  ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page1)
      

      since you use ScreenConfiguration in several qml components you would have to create ScreenConfigurationobjects multiple times..
      I would move the signal somewhere else and make ScreenConfiguration.qml singleton

      P 1 Reply Last reply
      1
      • ODБOïO ODБOï

        @Praveen-Illa said in Not able to handle Signals:

        qrc:/ScreenPage.qml:10:5: QML Connections: Detected function "onSampleButtonPressed" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.

        that is because of this

        Connections {
            target: ScreenConfiguration  //<<  target should be an object
        

        example :

        ScreenConfiguration { id: myConfig} // create an object 
        Connections {
            target: myConfig
        

        then HomeScreen.qml:28: TypeError: Property 'sampleButtonPressed' of object [object Object] is not a function
        same thing; you need an instance/object to access the signals/attributes

        onClicked: {
                    ScreenConfiguration.sampleButtonPressed(ScreenConfiguration.Pagenumbers.Page1)
        

        since you use ScreenConfiguration in several qml components you would have to create ScreenConfigurationobjects multiple times..
        I would move the signal somewhere else and make ScreenConfiguration.qml singleton

        P Offline
        P Offline
        Praveen.Illa
        wrote on last edited by
        #3

        @LeLev
        Thanks for your quick response, it works

        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