Results 1 to 6 of 6

Thread: MVC or not

  1. #1
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default MVC or not

    I will describe what's happening in my program.
    I have a main.cpp, list.cpp and custom_widget.cpp.
    In main.cpp, as usually it is, i have only:
    list->show();
    In list.cpp i create a list widget. Then i get information from XML, and call custom_widget.cpp to create custom widgets and then i add them to the list.
    In custom_widget.cpp i only create new custom widgets.

    My question - is this an example of MVC or not? I think that something is wrong. My supervisor told me i should do as follows:
    in list.cpp i need to fill an array with data and pass it to custom_widget.cpp
    In custom_widget.cpp i need to create custom widgets and pass them back.
    Then in List.cpp i need to fill the list.
    Is he right?

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MVC or not

    QListWidget uses Model/View internally, but the way I understand you have it set up is probably not MVC. Read the Model/View documentation for more information on model/view setups.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MVC or not

    I already read those, but they are written about QListView and such, and not about QListWidget... I cannot understand what part of my realization is wrong.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: MVC or not

    I have a main.cpp, list.cpp and custom_widget.cpp.
    The file names in your project are not relevant to the issue.
    One can only guess what is going on (as is code) in any of the files, and if they have classes in them, and what these classes do an how.

    Nothing and everything in what you said could be related to MVC, but probably nothing, since you did not say anything about data models.

    Did you read the Qt MVC docs?

    Is he right?
    If he is the boss, he is right!
    But seriously, you are talking about design lines, but provide to little (relevant) information to help you.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MVC or not

    The thing is, as i understood, to set the data in those QListView u need to use delegates, but using QListWidget u can use something like:
    Qt Code:
    1. listWidget->setItemWidget(listWidget->item(a), new Custom_Widget(titleString, dateString, aboutString, pictureString));
    To copy to clipboard, switch view to plain text mode 
    Is there anyway to use models while using QListWidget?

  6. #6
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MVC or not

    Hmm. QListWidget is a so called 'convenience class'. It is a QListView with it's model (a QAbstractListModel derivative) built into it. Internally, the QListWidget is definitely Model/View, but the code using it probably isn't. To make your implementation according to MVC, you would need to implement your own QAbstractItemModel derivative and feed it to a view. MVC is really about splitting up responsibilities: wherever you have to worry about displaying (view), do only displaying, wherever you have to worry about the data (model), do only data management. Using QListWidget more or less forces you in the 'wrong' i.e. non-MVC direction.

    Also, using delegates is different from setting item widgets. Moreover, using delegates is probably the better course of action to take.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  7. The following user says thank you to franz for this useful post:

    Archa4 (7th February 2011)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.