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

Romain Vimont rom1v at videolabs.io
Thu Dec 17 12:40:45 UTC 2020


On Thu, Dec 17, 2020 at 01:32:50PM +0100, Pierre Lamot wrote:
>   The count property might be accessed before browsing the model.

But if that's the case, m_cache should be nullptr, and the current
implementation should work, doesn't it?

> ---
>  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;

Is rowCount() called while medialib is not set yet?
I'm surprised, because the medialib is passed as a QML property, it
should be called before any rowCount() I guess.

>  
>      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
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list