Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Model Roles with children C++ classes
Forum Updated to NodeBB v4.3 + New Features

Model Roles with children C++ classes

Scheduled Pinned Locked Moved Solved QML and Qt Quick
c++qml
8 Posts 3 Posters 775 Views 2 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.
  • K Offline
    K Offline
    Karim
    wrote on last edited by
    #1

    Hi,

    I'm currently pototyping a kind of AVOD portal in QML with a Qt based C++ backend for the media catalog.
    I basically have a kind of MediaObject base c++ class with children classes for MediaMovie, MediaAudio (mp3, albums) and MediaStream.

    I've planed to implement a flickable object with each media cover, and as soon as a media is selected, display the related media data, depending of its type (movie, audio or stream).

    Until then, I've never faced this issue, I used to have a model with roles accessed in the delegate.

    In that particular case, roles might depend on the type of the media. In C++, this case might be fixes with the visitor pattern.
    But how could it be handled with QML ?

    Any suggestion is welcome.

    Cheers.

    K.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #6

      @Karim said in Model Roles with children C++ classes:

      But how could it be handled with QML ?

      DelegateChooser

      C++ is a perfectly valid school of magic.

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

        Hi,

        You may have missed the Qt Quick model view chapter in Qt's documentation. I think it should contain the information you are looking for.

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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Karim
          wrote on last edited by
          #3

          Hello,

          Of course I already read it for a while !
          But its content is not focused on model with model-data classes with inheritance.

          K

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

            You would like something like a dynamic delegate to match the underlying object ?

            How big are the differences between your media classes ?

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

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by fcarney
              #5

              If you want to return a QAbstractList/ItemModel you can do that as a role:

                   QVariant value;
              ...
                   case modelRole:
              
                      value = QVariant::fromValue(m_somemodel); // object based upon QObject* or QAbstractItemModel* or similar
                      break;
              

              Edit: This is in the data() function call and value is returned.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #6

                @Karim said in Model Roles with children C++ classes:

                But how could it be handled with QML ?

                DelegateChooser

                C++ is a perfectly valid school of magic.

                K 1 Reply Last reply
                1
                • K Offline
                  K Offline
                  Karim
                  wrote on last edited by
                  #7

                  @fcarney said in Model Roles with children C++ classes:

                  @Karim said in Model Roles with children C++ classes:

                  But how could it be handled with QML ?

                  DelegateChooser

                  @fcarney

                  Sorry for my late reply, I was sick off.
                  Thanks for your feedback, I'll try your suggestion and let you know...but it makes sense at first glance.

                  1 Reply Last reply
                  0
                  • fcarneyF fcarney

                    @Karim said in Model Roles with children C++ classes:

                    But how could it be handled with QML ?

                    DelegateChooser

                    K Offline
                    K Offline
                    Karim
                    wrote on last edited by
                    #8

                    @fcarney

                    Thanks. It solves my issue !

                    1 Reply Last reply
                    1

                    • Login

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