Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Connections when target is of type QList
Qt 6.12 LTS is out! See what's new in the release blog

Connections when target is of type QList

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 310 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.
  • Y Offline
    Y Offline
    Yazid10
    wrote on last edited by
    #1

    Hi everyone,

    Connections
        {
            target: manager.book
            function onPageListChanged()
            {
                pageThumbnailPanel.updateList(manager.book.pageList)
            }
        }
    

    In this code, we make a connection connection between a manager object and a book which is a manager property. The purpose of this connection and function is to update the list of pages based on changes in the pageList property of manager.book

    manager and book are both set as context properties

    pageList is defined in Book.h :

    Q_PROPERTY(QList<Page*> pageList READ pageList WRITE setPageList NOTIFY pageListChanged)
    

    Now I want to make a connection between each page of the book and the elements contained in a page. elementList is defined in Page.h :

    Q_PROPERTY(QList<Element*> elementList READ elementList WRITE setElementList NOTIFY elementListChanged)
    

    I tried to do something like this :

    Connections
        {
            target: manager.book.pageList
    
            function onElementListChanged()
            {
                for(var i=0; i < manager.book.pageList.length; i++)
                {
                    var currentPage = manager.book.pageList[i];
                    pagePanel.updateElementList(manager.book.pageList[i].elementList)
                }
    
            }
        }
    

    But didnt work.

    Any idea how to correct it ? Thanks in advance

    jeremy_kJ 1 Reply Last reply
    0
    • Y Yazid10

      Hi everyone,

      Connections
          {
              target: manager.book
              function onPageListChanged()
              {
                  pageThumbnailPanel.updateList(manager.book.pageList)
              }
          }
      

      In this code, we make a connection connection between a manager object and a book which is a manager property. The purpose of this connection and function is to update the list of pages based on changes in the pageList property of manager.book

      manager and book are both set as context properties

      pageList is defined in Book.h :

      Q_PROPERTY(QList<Page*> pageList READ pageList WRITE setPageList NOTIFY pageListChanged)
      

      Now I want to make a connection between each page of the book and the elements contained in a page. elementList is defined in Page.h :

      Q_PROPERTY(QList<Element*> elementList READ elementList WRITE setElementList NOTIFY elementListChanged)
      

      I tried to do something like this :

      Connections
          {
              target: manager.book.pageList
      
              function onElementListChanged()
              {
                  for(var i=0; i < manager.book.pageList.length; i++)
                  {
                      var currentPage = manager.book.pageList[i];
                      pagePanel.updateElementList(manager.book.pageList[i].elementList)
                  }
      
              }
          }
      

      But didnt work.

      Any idea how to correct it ? Thanks in advance

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      @Yazid10 said in Connections when target is of type QList:

      But didnt work.

      Any idea how to correct it ? Thanks in advance

      Skipping to the most important part, what does didn't work mean? If there's a compiler or runtime error, include that. If your computer experienced a sudden unexpected self-dissassembly, details please. correct may also require some explanation.

      pageList is defined in Book.h :

      [...]

      Now I want to make a connection between each page of the book and the elements contained in a page. elementList is defined in Page.h :

      Try to minimize references to different files. C++ has compilation units, but not "files". Inline rather than giving us .cpp and .h files.

      I tried to do something like this :

      Connections
          {
              target: manager.book.pageList
      

      From the previous definition of the pageList property, this may be a manifestation of a documentation failure that has been corrected:
      https://doc.qt.io/qt-6/qml-qtqml-connections.html#target-prop

      target : QtObject

      This property holds the object that sends the signal.

      In the past, target was specified as Object rather than QtObject. The description states that target should be able to emit a signal, ie be a QObject. A QList property is not a QObject, and therefore can not be a valid Connections target.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      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
      • Unsolved