Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating QTableView dynamically / Creating new playlists
Qt 6.12 LTS is out! See what's new in the release blog

Creating QTableView dynamically / Creating new playlists

Scheduled Pinned Locked Moved Solved General and Desktop
34 Posts 4 Posters 21.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H hbatalha

    @JonB said in Creating QTableView dynamically / Creating new playlists:

    @hbatalha
    As I wrote earlier, you need to use QAbstractItemModel::beginResetModel() when you change models. See e.g. https://stackoverflow.com/questions/14756645/how-to-reset-model-in-qt.

    The playlist model inherits from QAbstractTableModel as shown in the code above

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by
    #21

    @hbatalha
    Yes, and what does that inherit from...?

    H 1 Reply Last reply
    0
    • JonBJ JonB

      @hbatalha
      Yes, and what does that inherit from...?

      H Offline
      H Offline
      hbatalha
      wrote on last edited by
      #22

      @JonB
      IbeginResetModel is protected. https://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

      JonBJ 1 Reply Last reply
      0
      • H hbatalha

        @JonB
        IbeginResetModel is protected. https://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #23

        @hbatalha said in Creating QTableView dynamically / Creating new playlists:

        beginResetModel is protected. https://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

        You wrote earlier

        The playlist model inherits from QAbstractTableModel as shown in the code above

        So that means you can call protected methods, doesn't it?

        If you have some aversion to resetting the model, you can probably delete all existing rows and insert all new rows if you really wish.

        H 1 Reply Last reply
        0
        • JonBJ JonB

          @hbatalha said in Creating QTableView dynamically / Creating new playlists:

          beginResetModel is protected. https://doc.qt.io/qt-5/qabstractitemmodel.html#beginResetModel

          You wrote earlier

          The playlist model inherits from QAbstractTableModel as shown in the code above

          So that means you can call protected methods, doesn't it?

          If you have some aversion to resetting the model, you can probably delete all existing rows and insert all new rows if you really wish.

          H Offline
          H Offline
          hbatalha
          wrote on last edited by
          #24

          @JonB said in Creating QTableView dynamically / Creating new playlists:

          So that means you can call protected methods, doesn't it?

          That is what I expected, I am finding strange that the compiler is complaining that it is protected.

          JonBJ 1 Reply Last reply
          0
          • H hbatalha

            @JonB said in Creating QTableView dynamically / Creating new playlists:

            So that means you can call protected methods, doesn't it?

            That is what I expected, I am finding strange that the compiler is complaining that it is protected.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #25

            @hbatalha
            If you are trying to go

            m_model.beginResetModel();
            m_model.setPlaylist(*m_playlists.at(ui->comboBox->currentIndex()));
            m_model.endResetModel();
            

            you cannot do that on protected methods. You must call them in PlaylistModel::setPlaylist().

            H 1 Reply Last reply
            0
            • JonBJ JonB

              @hbatalha
              If you are trying to go

              m_model.beginResetModel();
              m_model.setPlaylist(*m_playlists.at(ui->comboBox->currentIndex()));
              m_model.endResetModel();
              

              you cannot do that on protected methods. You must call them in PlaylistModel::setPlaylist().

              H Offline
              H Offline
              hbatalha
              wrote on last edited by
              #26

              @JonB said in Creating QTableView dynamically / Creating new playlists:

              you cannot do that on protected methods. You must call them in PlaylistModel::setPlaylist().

              yeah I fixed that.

              But still, the playlist will be empty when I switch. I must be missing something.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #27

                Where/when are you putting stuff in that playlist ?
                You only show that you created it but at no point you seem to put anything in it.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                1
                • SGaistS SGaist

                  Where/when are you putting stuff in that playlist ?
                  You only show that you created it but at no point you seem to put anything in it.

                  H Offline
                  H Offline
                  hbatalha
                  wrote on last edited by
                  #28

                  @SGaist There is a drop event where the files added to the playlist will be at the same time added to the playlist vector current element (m_playlists.at(ui->comboBox->currentIndex())).

                  But I since discovered that the Mlt::Playlist doesn't allow copying. When I set a playlist (m_model.setPlaylist(*m_playlists.at(ui->comboBox->currentIndex())); ) the m_model.playlist() takes omership of all the elements in the playlist and when I switch to another playlist they get deleted. Here is the Mlt::Playlist interface:

                  class MLTPP_DECLSPEC Playlist : public Producer
                  	{
                  		private:
                  			mlt_playlist instance;
                  		public:
                  			Playlist( );
                  			Playlist( Profile& profile );
                  			Playlist( Service &playlist );
                  			Playlist( Playlist &playlist );
                  			Playlist( mlt_playlist playlist );
                  			virtual ~Playlist( );
                  			virtual mlt_playlist get_playlist( );
                  			mlt_producer get_producer( );
                  			int count( );
                  			int clear( );
                  			int append( Producer &producer, int in = -1, int out = -1 );
                  			int blank( int out );
                  			int blank( const char *length );
                  			int clip( mlt_whence whence, int index );
                  			int current_clip( );
                  			Producer *current( );
                  			ClipInfo *clip_info( int index, ClipInfo *info = NULL );
                  			static void delete_clip_info( ClipInfo *info );
                  			int insert( Producer &producer, int where, int in = -1, int out = -1 );
                  			int remove( int where );
                  			int move( int from, int to );
                  			int reorder( const int *indices );
                  			int resize_clip( int clip, int in, int out );
                  			int split( int clip, int position );
                  			int split_at( int position, bool left = true );
                  			int join( int clip, int count = 1, int merge = 1 );
                  			int mix( int clip, int length, Transition *transition = NULL );
                  			int mix_in( int clip, int length );
                  			int mix_out( int clip, int length );
                  			int mix_add( int clip, Transition *transition );
                  			int repeat( int clip, int count );
                  			Producer *get_clip( int clip );
                  			Producer *get_clip_at( int position );
                  			int get_clip_index_at( int position );
                  			bool is_mix( int clip );
                  			bool is_blank( int clip );
                  			bool is_blank_at( int position );
                  			void consolidate_blanks( int keep_length = 0 );
                  			Producer *replace_with_blank( int clip );
                  			void insert_blank( int clip, int out );
                  			void pad_blanks( int position, int length, int find = 0 );
                  			int insert_at( int position, Producer *producer, int mode = 0 );
                  			int insert_at( int position, Producer &producer, int mode = 0 );
                  			int clip_start( int clip );
                  			int clip_length( int clip );
                  			int blanks_from( int clip, int bounded = 0 );
                  			int remove_region( int position, int length );
                  	};
                  

                  And here is the PlaylistModel::setPlaylist:

                  void PlaylistModel::setPlaylist(Mlt::Playlist& playlist)
                  {
                      if (playlist.is_valid()) {
                          if (m_playlist) {
                              if (rowCount()) {
                                  beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
                                  m_playlist->clear();
                                  endRemoveRows();
                              }
                              delete m_playlist;
                          }
                          m_playlist = new Mlt::Playlist(playlist);
                          if (!m_playlist->is_valid()) {
                              delete m_playlist;
                              m_playlist = 0;
                              return;
                          }
                          if (m_playlist->count() > 0) {
                              beginInsertRows(QModelIndex(), 0, m_playlist->count() - 1);
                              endInsertRows();
                          }
                          // do not let opening a clip change the profile!
                          MLT.profile().set_explicit(true);
                          if (Settings.playerGPU() && Settings.playlistThumbnails() != "hidden")
                              refreshThumbnails();
                          emit loaded();
                      }
                  }
                  

                  I tried creating vector that hold the actual filenames and then every time I switch to playlist I would clear the m_model.playlist and add the new files but that process is slow, specially when you have multiple files, so that was not not a option.

                  I can't think of any other way now, I looking into using a vector of models.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #29

                    Why are you trying to pass reference around rather than pointers ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Why are you trying to pass reference around rather than pointers ?

                      H Offline
                      H Offline
                      hbatalha
                      wrote on last edited by
                      #30

                      @SGaist I am not, that is how Mlt::Playlist works.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #31

                        You do that in your PlaylistModel. You are passing everything by reference although you store all your PlayLists as pointers. Hence fail to see why you are using references in you model interface. Also why are you creating so many copies of your PlayList objects ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        H 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          You do that in your PlaylistModel. You are passing everything by reference although you store all your PlayLists as pointers. Hence fail to see why you are using references in you model interface. Also why are you creating so many copies of your PlayList objects ?

                          H Offline
                          H Offline
                          hbatalha
                          wrote on last edited by hbatalha
                          #32

                          @SGaist said in Creating QTableView dynamically / Creating new playlists:

                          You are passing everything by reference although you store all your PlayLists as pointers.

                          That's how I found the code. However I changed that, but it crashes every time I switch back to a playlist:

                          void PlaylistModel::setPlaylist(Mlt::Playlist *playlist)
                          {
                              if (playlist->is_valid())
                              {
                                  if (m_playlist)
                                  {
                                      if (rowCount())
                                      {
                                          beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
                          //                m_playlist->clear();
                                          endRemoveRows();
                                      }
                                      // delete m_playlist;
                                  }
                                  m_playlist = playlist; // crashes here
                                  if (!m_playlist->is_valid())
                                  {
                                      // delete m_playlist;
                                      m_playlist = 0;
                                      return;
                                  }
                                  if (m_playlist->count() > 0)
                                  {
                                      beginInsertRows(QModelIndex(), 0, m_playlist->count() - 1);
                                      endInsertRows();
                                  }
                                  // do not let opening a clip change the profile!
                                  MLT.profile().set_explicit(true);
                                  if (Settings.playerGPU() && Settings.playlistThumbnails() != "hidden")
                                      refreshThumbnails();
                                  emit loaded();
                              }
                          }
                          ``
                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #33

                            One thing you should do: call begin/endResetModel when you replace the playlist.

                            Then, the debugger is your friend.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            H 1 Reply Last reply
                            1
                            • SGaistS SGaist

                              One thing you should do: call begin/endResetModel when you replace the playlist.

                              Then, the debugger is your friend.

                              H Offline
                              H Offline
                              hbatalha
                              wrote on last edited by
                              #34

                              @SGaist That did it, can't thank you enough.

                              Thank you all for the time and help.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt
                              • Unsolved