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. Cannot figure out Connections{} for signal

Cannot figure out Connections{} for signal

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 707 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.
  • B Offline
    B Offline
    ButterBoubon
    wrote on last edited by
    #1
    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        signal testSignal()
    
        Rectangle {
            id:testRec
            property string colorVar: "blue"
            width:400
            height:400
            color: colorVar
            Connections {
                target: testRec
                onTestSignal: colorVar = "red" //Cannot assign to non-existent property "onTestSignal"
            }
        }
        Button{
            width:100
            height:100
            text: "Button"
            onClicked: {
                console.log("button pressed")
                testSignal()
            }
        }
    }
    

    Hi Guys

    For the life of me I can't figure out what I might be doing wrong here.
    I can't get on<signal> to work at all. I've tried numerous examples and always get this error: Cannot assign to non-existent property "onTestSignal"

    I've tried just adding on<signal> without the Connections{}
    Also with and without target
    Also ontestSignal: and onTestsignal:

    If I type on<signal> without the Connections{} it always has a red line under it.. error invalid property name, and doesn't run at all. with Connections{} it runs and gives an error without the button being pressed.

    Is there maybe some import I am missing?

    Thanks

    ODБOïO 1 Reply Last reply
    0
    • B ButterBoubon
      import QtQuick 2.9
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.2
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
          signal testSignal()
      
          Rectangle {
              id:testRec
              property string colorVar: "blue"
              width:400
              height:400
              color: colorVar
              Connections {
                  target: testRec
                  onTestSignal: colorVar = "red" //Cannot assign to non-existent property "onTestSignal"
              }
          }
          Button{
              width:100
              height:100
              text: "Button"
              onClicked: {
                  console.log("button pressed")
                  testSignal()
              }
          }
      }
      

      Hi Guys

      For the life of me I can't figure out what I might be doing wrong here.
      I can't get on<signal> to work at all. I've tried numerous examples and always get this error: Cannot assign to non-existent property "onTestSignal"

      I've tried just adding on<signal> without the Connections{}
      Also with and without target
      Also ontestSignal: and onTestsignal:

      If I type on<signal> without the Connections{} it always has a red line under it.. error invalid property name, and doesn't run at all. with Connections{} it runs and gives an error without the button being pressed.

      Is there maybe some import I am missing?

      Thanks

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

      Hi,

      @ButterBoubon said in Cannot figure out Connections{} for signal:

      I can't figure out what I might be doing wrong here

      The Connections has testRec as target, so the signal must be declared inside testRec

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
      
          Connections {
              target: testRec
             // onTestSignal: colorVar = "red" //Cannot assign to non-existent property "onTestSignal"
                  onTestSignal: testRec.color="red"
          }
              Rectangle {
                  id:testRec
                  signal testSignal()
                 // property string colorVar: "blue" // Invalid write to global property
                  width:400
                  height:400
                  color: "green"
      
              }
              Button{
                  width:100
                  height:100
                  text: "Button"
                  onClicked: {
                      console.log("button pressed")
                      testRec.testSignal()
                  }
              }
      }
      

      More flexible approch is to declare the testRec in separat .qml Component file

      1 Reply Last reply
      1
      • B Offline
        B Offline
        ButterBoubon
        wrote on last edited by
        #3

        Thank you!

        I separate all my items into separate qml files. I just put together a quick thing not to overload the question with too much info. It makes things so much more less confusing.

        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