From 270cb67570ec1538006202504f5d24dc2a5bda5f Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 19 Apr 2023 14:16:38 -0500 Subject: [PATCH] Trying to tweak the image_model for a better count function Apparently there is a bug in the way these functions are called from QML so we aren't getting the count of items in the library. All other functions seem to be working but not this, so I tried a property and the same situation... --- src/rust/image_model.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/rust/image_model.rs b/src/rust/image_model.rs index 9d3fb33..2df2f1b 100644 --- a/src/rust/image_model.rs +++ b/src/rust/image_model.rs @@ -39,6 +39,8 @@ mod image_model { #[cxx_qt::qobject(base = "QAbstractListModel")] #[derive(Default, Debug)] pub struct ImageModel { + #[qproperty] + count_rows: i32, highest_id: i32, images: Vec, } @@ -355,13 +357,16 @@ mod image_model { #[qinvokable(cxx_override)] pub fn row_count(&self, _parent: &QModelIndex) -> i32 { let cnt = self.rust().images.len() as i32; + // self.as_mut().set_count(cnt); // println!("row count is {cnt}"); cnt } #[qinvokable] - pub fn count(&self) -> i32 { - self.rust().images.len() as i32 + pub fn count(mut self: Pin<&mut Self>) -> i32 { + let cnt = self.rust().images.len() as i32; + self.as_mut().set_count_rows(cnt); + cnt } } }