Connections when target is of type QList
-
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
-
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
@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 workmean? If there's a compiler or runtime error, include that. If your computer experienced a sudden unexpected self-dissassembly, details please.correctmay 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.pageListFrom 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-proptarget : 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.