Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Qml, connect to SIGNAL from component created in parent scope

[SOLVED]Qml, connect to SIGNAL from component created in parent scope

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.3k 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.
  • T Offline
    T Offline
    TT_NBE
    wrote on last edited by
    #1

    Hello,

    In my main.qml file I create and instance of an object defined in the c++ backend. Further the main.qml file contains a stackview on which views are pushed and popped (from user input or signals from the c++ object). Each view is in its own qml file.

    In the main.qml and the qml files for the different views I can bind to Q_PROPERTY's from the c++ object.

    In the definition of the c++ object in the main.qml I can also connect to Signals from the c++ object.

    But what I can't do is to connect to signlas from the c++ object in on of the child views.

    Some code the clarify
    main.qml
    @ApplicationWindow {
    id: applicationWindow1
    visible: true
    width: 800
    height: 600

    BackendObject
    {
          id: myObject
          onSignalA{stackView.push(Qt.resolvedUrl("ViewA")}   //works
          onSignalB{.....}    //works
          ....
    }
     
    StackView
    {
          initialItem: stackView.push(Qt.resolvedUrl("InitialView")
          ......
    }
    @
    

    The ViewA.qml
    @
    Item
    {
    Text:
    {
    text:myObject.TextProperty //databind to text property (works)
    }

        myObject.onSignalB{... }//this does not work, the entire view is'nt displayed but there is no output in the console
    

    }
    @

    Anybody an idea as on how to solve this?
    (I could create a property and change the property instead of emitting the signal, but that seems like a lot of overhead code).

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TT_NBE
      wrote on last edited by
      #2

      OK, figured this out: a connections items is needed. The update view A will look like this:

      @
      Item
      {
      Text:
      {
      text:myObject.TextProperty //databind to text property (works)
      }

          Connections
          {
               target: myObject
               onSignalB {......}//this 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