Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Doubts about breaking Model View separation
Qt 6.11 is out! See what's new in the release blog

Doubts about breaking Model View separation

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 488 Views
  • 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.
  • U Offline
    U Offline
    user13
    wrote on last edited by user13
    #1

    If i have a Model like the following

    class Model : public QAbstractListModel {
    private:
      QList<Base*> _data;
    public:
      //virtual functions of the base class : insertRow(), data(), etc...
    
      void insertObject(Base* ptr) { _data.push_back(ptr) };
    };
    

    where Base is the base class of a hierarchy :

    class Base {};
    class Derived1 : public Base {};
    class Derived2 : public Base {};
    

    Is it possible to call Derived1 constructor in a slot of a QWidget to create a new object to insert in model::_data?
    Any help would be highly appreciated!

    Link to the repo with a working example (see AddDialog class)

    jsulmJ 1 Reply Last reply
    0
    • U user13

      If i have a Model like the following

      class Model : public QAbstractListModel {
      private:
        QList<Base*> _data;
      public:
        //virtual functions of the base class : insertRow(), data(), etc...
      
        void insertObject(Base* ptr) { _data.push_back(ptr) };
      };
      

      where Base is the base class of a hierarchy :

      class Base {};
      class Derived1 : public Base {};
      class Derived2 : public Base {};
      

      Is it possible to call Derived1 constructor in a slot of a QWidget to create a new object to insert in model::_data?
      Any help would be highly appreciated!

      Link to the repo with a working example (see AddDialog class)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @user13 said in Doubts about breaking Model View separation:

      Is it possible to call Derived1 constructor in a slot of a QWidget to create a new object to insert in model::_data?

      Sure, why not?
      What is the problem?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • U Offline
        U Offline
        user13
        wrote on last edited by
        #3

        Thank you for the reply!
        I was doubtful since I tought that a call to the constructor of an object, which is "managed" by the Model, from a slot in a QWidget would "break" the separation between Model and View.

        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 Extensions
        • Unsolved