[vlc-devel] [PATCH 3/3] qt: allow getCount to initiate the cache in MLBaseModel

Pierre Lamot pierre at videolabs.io
Thu Dec 17 12:32:50 UTC 2020


  The count property might be accessed before browsing the model.
---
 modules/gui/qt/medialibrary/mlbasemodel.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp
index 4549dacb57..68eb28dac9 100644
--- a/modules/gui/qt/medialibrary/mlbasemodel.cpp
+++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp
@@ -237,7 +237,7 @@ void MLBaseModel::unsetSortCriteria()
 
 int MLBaseModel::rowCount(const QModelIndex &parent) const
 {
-    if (parent.isValid())
+    if (!m_mediaLib || parent.isValid())
         return 0;
 
     validateCache();
@@ -302,7 +302,10 @@ QVariantList MLBaseModel::getIdsForIndexes(QVariantList indexes) const
 
 unsigned MLBaseModel::getCount() const
 {
-    if (!m_cache || m_cache->count() == COUNT_UNINITIALIZED)
+    if (!m_mediaLib)
+        return 0;
+    validateCache();
+    if (m_cache->count() == COUNT_UNINITIALIZED)
         return 0;
     return static_cast<unsigned>(m_cache->count());
 }
-- 
2.25.1



More information about the vlc-devel mailing list