ListView delegated Component{} sees outside only sometimes?
-
Hello guys...
so my scenario:
UPDATE:
for whatever reason all works fine until first API.feed() isnide onAtYEndChanged is triggered...
which makes me even more confused why this happensUPDATE2:
Ha, found a bug (i think)...
what I normaly did, is going on the top of ListView before refreshing the model, because I found it works better going on top, clear(), populate (rather then clear(), populate() -> because it puts you back to this ContentY as it remembers, then go to top (and during loading async images it will somehow jump little lower again)so if I use:
onClicked: { feed_listview.contentY = feed_listview.originY; // this brings error, but comment this line or put it after API.feed() then all works fine api_feed.autor = Math.floor(Math.random() * 100) + 1; api_feed.page = Math.floor(Math.random() * 100) + 1; API.feed(api_feed.page, api_feed.autor, false); // this brings the error, but how come that row before it can work with that just fine }
Main.qml:
import QtQuick import QtQuick.Controls import QtQuick.Layouts import "JavaScript_API.js" as API Window { id: root width: 375 height: 667 visibility: ApplicationWindow.Windowed color: "#262626" title: qsTr("test") // API Feed ListModel { id: api_feed onCountChanged: console.log("count: " + count) } property int api_feed_page: 1 onApi_feed_pageChanged: console.log("page: " + api_feed_page) property int api_feed_autor: 0 onApi_feed_autorChanged: console.log("autor: " + api_feed_autor) StackLayout { id: view anchors.fill: parent currentIndex: 0 Component.onCompleted: { API.feed(api_feed_page, api_feed_autor); //works perfect } // currentIndex: 0 Item { id: view_screenHome Screen_home {} } } }
Screen_home.qml:
import QtQuick //import QtQuick.Controls //import QtQuick.Layouts import Qt5Compat.GraphicalEffects // to be updated with new Qt 6.x.x verison, as FastBlue was canceled in Qt6 but its planned in newer version import "JavaScript_API.js" as API ListView { id: feed_listview anchors.fill: parent interactive: true boundsBehavior: Flickable.StopAtBounds flickableDirection: Flickable.VerticalFlick contentHeight: feed_content.height ? feed_content.height : parent.height model: api_feed delegate: feed_content onAtYEndChanged: { if (atYEnd && api_feed.count > 0) { console.log("rend reached, loading another 10..."); API.feed(api_feed_page++, api_feed_autor, true); // this works fine } } Component { id: feed_content Rectangle { width: feed_listview.width height: 100 color: "transparent" border.color: "blue" MouseArea { id: myarea anchors.fill: parent onClicked: { //feed_listview.contentY = feed_listview.originY; // uncomment here and you will have an error "Error: Invalid write to global property "api_feed_page"... however if I put it after API.feed() then no error... api_feed_autor = Math.floor(Math.random() * 100) + 1; // random number from 1 to 100, correctly debugs change for onAutorChanged api_feed_page = Math.floor(Math.random() * 100) + 1; // random number from 1 to 100, correctly debugs change for onPageChanged API.feed(api_feed_page, api_feed_autor, false); // this brings the error, but how come that row before it can work with that just fine } } } } }
JavaScript.js:
function feed(pPage, pAutor, add = false) { if (!add) { api_feed.clear(); } for (var ix = 0; ix < 10; ++ix) { api_feed.append({ "result_id": ix}); } return; }
and while I click in the MouseArea in Screen_home.qml i get the error:
Screen_home.qml:xx: ReferenceError: api_feed is not defined
which I highly do not undestand why... to my, it must see api_feed just fine... can anyone giveme hint why it can not recognize api_feed?
-