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. Make Connections to Loader depending on loaded File
Forum Updated to NodeBB v4.3 + New Features

Make Connections to Loader depending on loaded File

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 873 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by sandro4912
    #1

    I load a loader object with a specific file like this:

    onClicked: {
                        questionSqlTableModel.generateNewRandomQuestions(2)
                        loader.setSource("quiz/Quiz.qml",
                                         {"randomQuestions":
                                             questionSqlTableModel.randomQuestions})
                    }
    

    Now the page Quiz.qml emits a signal I need to wait for. This I can check with a Connection:

    Connections {
           target: loader.item
    
           function onFinnished(correctAnswers) {
               console.log("correct Answer: " +  correctAnswers)
           }
       }
    

    Now my loader can also load other pages:

                ToolButton {
                    text: qsTr("Show Table")
                    icon.name: "document-open"
                    onClicked: {
                        loader.setSource("sql_table_view/SqlTableView.qml")
                    }
                }
    

    Do I have to dynamically enable disable the Connection depending on the content? If yes how can I only listen for the connection if a specific file is loaded?

    Like

    Load file A connect to Signal B emitted from A
    Load file C connect to Signal D emitted from C

    edit: do I have to set ignoreUnknownSignals to false when the page is not loaded from Connections or active = false ?

    edit:

    I tired to disable the Connection when loading another element like this:

    Connections {
        id: quizConnections
        target: loader.item
    
        function onFinnished(correctAnswers) {
            console.log("correct Answer: " +  correctAnswers)
            quizConnections.enabled = false
            loader.setSource("result/Result.qml")
        }
    }
    

    But then I get this error:

    QML Connections: Detected function "onFinnished" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @sandro4912 said in Make Connections to Loader depending on loaded File:

      do I have to set ignoreUnknownSignals to false when the page is not loaded from Connections or active = false ?

      use active property. You don't need to call it in the slot, you can do it declaratively instead:

      Connections {
          id: quizConnections
          target: loader.item
          active: loader.source === "quiz/Quiz.qml"
      
          function onFinnished(correctAnswers) {
              console.log("correct Answer: " +  correctAnswers)
          }
      }
      

      Or even set the target only when needed:

      Connections {
          id: quizConnections
          target: loader.source === "quiz/Quiz.qml"? loader.item : undefined
      
          function onFinnished(correctAnswers) {
              console.log("correct Answer: " +  correctAnswers)
          }
      }
      

      (Z(:^

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sandro4912
        wrote on last edited by
        #3

        @sierdzio said in Make Connections to Loader depending on loaded File:

        Connections {
        id: quizConnections
        target: loader.item
        active: loader.source === "quiz/Quiz.qml"

        function onFinnished(correctAnswers) {
            console.log("correct Answer: " +  correctAnswers)
        }
        

        }

        That gives error:

        Cannot assign to non-existent property "active"
        

        I tried instead:

        enabled: loader.source === "quiz/Quiz.qml"
        

        which gives still:

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

        I think to surpress the warning we have to set ignoreUnknownSignals to true aswell

        sierdzioS 1 Reply Last reply
        0
        • S sandro4912

          @sierdzio said in Make Connections to Loader depending on loaded File:

          Connections {
          id: quizConnections
          target: loader.item
          active: loader.source === "quiz/Quiz.qml"

          function onFinnished(correctAnswers) {
              console.log("correct Answer: " +  correctAnswers)
          }
          

          }

          That gives error:

          Cannot assign to non-existent property "active"
          

          I tried instead:

          enabled: loader.source === "quiz/Quiz.qml"
          

          which gives still:

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

          I think to surpress the warning we have to set ignoreUnknownSignals to true aswell

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @sandro4912 said in Make Connections to Loader depending on loaded File:

          I think to surpress the warning we have to set ignoreUnknownSignals to true aswell

          Yeah in that case it seems like a good choice.

          (Z(:^

          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