QtDay: Back to Basics: writing a model - a workshop by Giuseppe D'Angelo, KDAB

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ก.ค. 2024
  • 0:00 Intro to Workshop
    3:25 Beginning of Workshop
    9:50 Model/View in Qt: Basic Concepts
    25:28 Model Structure
    48:02 QAbstractItemModel API
    1:08:35 Creating a List Model
    1:48:25 Handling Modifications
    2:02:25 Going further (bonus slides)
    This workshop by KDAB's Giuseppe D'Angelo was presented at QtDay Italy 20. QtDay gathers Qt experts from all over the world and is entirely focused on Qt and Qt-related technologies. The event is organized by Develer.
    qtday.it/
    www.develer.com/en/
    In 2020, let’s go “back to basics”. Writing model/view code is somehow given for granted. It’s however a mandatory skill for any proficient Qt developer: professionals are supposed to be able to write robust, fast, tested models. We’ll see how together in this workshop.
    Any non-trivial Qt application will feature usages of the model/view/controller framework. MVC is a well known design pattern, embracing separation of concerns between managing the data and the user interface that is supposed to visualize and manipulate it.
    In this workshop I will focus on the “model” aspect of the MVC framework; that is, the part that interacts directly with the data. Models play a central role in Qt, no matter what’s the UI stack used with of them (Qt Widgets, Qt Quick, remote objects, …). Whilst it’s very rare to develop custom views, it’s instead very very typical for Qt developers to develop custom models; in my professional experience I must have developed hundreds of them.
    So, what is exactly a model in Qt’s MVC design? How do we write one? What is the developer’s responsibility, and what instead is provided by Qt, maybe as convenience? What are the performance characteristics of models? And how do we test one? The answers are not so trivial, and it’s important to nail them down to write robust model code that will drive the rest of our user interface.
    In this workshop we will write together some models, use them in combination with some views, and while doing so, show all the best practices associated with such development. In a few places we are going to use some classes or functions that I have contributed to Qt in order to help our development.
    At the end, you will have gained some deep understanding about what is the intended usage of models in Qt.
    About KDAB:
    KDAB offers experienced software experts to help you deliver functional, high-performing and innovative software across embedded, mobile and desktop platforms for projects using C++, Qt, QML/Qt Quick, OpenGL, Qt 3D and more. www.kdab.com/software-services
    KDAB experts regularly take time out to deliver KDAB’s world class training, in-house or at open enrollment courses around the world. We are the market leaders for training in Qt, OpenGL and C++.
    Contact us to find out more at training@kdab.com or visit our website: www.kdab.com/software-service...
    We are about 90 people, located all around the world. Our Head Office is in Sweden and we have other offices in Germany, France, the UK and the USA. www.kdab.com/about/contact/
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 29

  • @vladimirkraus1438
    @vladimirkraus1438 3 ปีที่แล้ว +9

    This is the best explanation of views, models etc. which I have seen.

  • @renemuniz9310
    @renemuniz9310 9 หลายเดือนก่อน +1

    This is, by far, the best presentation I've found around about this topic. Thanks a lot for sharing!

  • @manonthedollar
    @manonthedollar 3 ปีที่แล้ว +5

    This was a great presentation. Thank you! I always intend to treat QAbstractItemModel as an adapter class, but I find myself always having to tailor the model specifically to QAIM's needs. Especially in resolving the parent and things like that.

  • @Debjit625
    @Debjit625 11 หลายเดือนก่อน

    Great presentation,thanks Giuseppe D'Angelo , KDAB and QtDay Italy.👍

    • @KDABtv
      @KDABtv  11 หลายเดือนก่อน

      Thank you! :)

  • @scopchanov
    @scopchanov ปีที่แล้ว +2

    This is an amazing video - very well presented and trully informative! Thank you very much for sharing these insights and for the wonderful examples!

    • @KDABtv
      @KDABtv  ปีที่แล้ว +1

      Hi Michael! :)
      Thank you very much! We're very happy that you like the video!

  • @mrj1997
    @mrj1997 ปีที่แล้ว

    one of most valuable talks I ever seen
    I don't know how to thank you
    Thank you very very very much!

  • @zaregg.
    @zaregg. 3 ปีที่แล้ว +2

    Thank you for this!! Ive been trying to find a good video about this for while. I'm working on a school project and ive been stuck on this for weeks.

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว +1

      We're glad we could help!

  • @romanvldn
    @romanvldn 3 ปีที่แล้ว +1

    Thanks for a super simple explanation of a complex concept

  • @pawanadhikari110
    @pawanadhikari110 ปีที่แล้ว

    Really great presentation.

  • @gokhan_turan
    @gokhan_turan 3 ปีที่แล้ว +1

    Thank you very much for the nice presentation!!

  • @Eric-im6nn
    @Eric-im6nn 2 ปีที่แล้ว

    This is professional, thanks for sharing!

  • @jeevanreddy7989
    @jeevanreddy7989 ปีที่แล้ว

    great presentation.extremely insightful & highly informative!! Thank you.

  • @marcm7533
    @marcm7533 2 ปีที่แล้ว

    Thank you very much! Very very usefull!

    • @KDABtv
      @KDABtv  2 ปีที่แล้ว

      Hi Marc!
      Thank you for the feedback! :)

  • @kruplattila
    @kruplattila ปีที่แล้ว +1

    Hi, this was a very useful video, thanks for that. Giuseppe, one question if you're still watching this thread: you told that models don't hold the data, just serve it to the view, but you added the values to your list within your example model. That's a little confusing. Do you mean by "not holding the data", that models should receive the complex data objects via pointers/references?

    • @giuseppedangelo3015
      @giuseppedangelo3015 ปีที่แล้ว +2

      Hi,
      You're right! My example was a (very) simplified version of a model class, where I chose to store the data into the model itself. The point is that this is not a "requirement" by any means. On the contrary, usually the data is *not* stored into the model, but the model is just an adaptor between the actual storage (a data structure in memory, a database, ...) and a view.
      How exactly does the model access the data is an "implementation detail" of the model -- it really depends on what the actual storage looks like. So it's not really about C++ pointers/references themselves (it could be iterators, a "cursor" class in case of SQL storage, etc.). In short, it depends :-)

  • @berkdan
    @berkdan ปีที่แล้ว

    Great tutorial. Thanks.If the source data changes how coud we notify the view to change it's data.

    • @giuseppedangelo3015
      @giuseppedangelo3015 ปีที่แล้ว +1

      Hi, thank you. You're simply supposed to emit the dataChanged() signal to notify views which indexes have changed.

  • @zaregg.
    @zaregg. 3 ปีที่แล้ว

    If you have a server where you get a lot of different data from, how would you update the model every time specific data changes when you receive new data and you parsed it? The data is stored in QVariantHash, and is received at different intervals.

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว +1

      The question is not an easy one. It fundamentally depends on what kind of "updates" are sent by the server, and if the model is keeping a local copy (cache) of the data.
      If the updates match 1:1 with the expected Qt model API (e.g. data changed, rows inserted, rows removed, etc.) then it's easy to handle such updates -- just use the right notifications when an update is received, and, of course, also refresh the data in the local copy.
      If the server simply sends "snapshots" of the data, then you can use an approach like UpdateableModel from KDToolBox (link below), which will translate the new snapshot in the right set of signals for your model.
      ecs.page.link/iBvJB

  • @deadmarshal
    @deadmarshal 2 ปีที่แล้ว

    We need a video like this for QTreeView with QAbstractItemModel please. thank you!

    • @KDABtv
      @KDABtv  2 ปีที่แล้ว

      Hi!
      We've got a Qt Widgets and more episode on QAbstractItemModel, which you can find following this link:
      th-cam.com/video/Tm1nNyM6Upk/w-d-xo.html

  • @michelledupuis3495
    @michelledupuis3495 3 ปีที่แล้ว

    I'm confused by what I think is multiple names for the same thing: QModelIndex / ModelIndex / Index / Cell / Element. Are they all same?

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว

      Hi Michelle!
      Yes, they're used a bit interchangeably. QModelIndex is of course the API, and it refers to a specific position in a model, usually called cell/element.

  • @madmuppet2k
    @madmuppet2k 3 ปีที่แล้ว +1

    Where can we get the slides?

    • @KDABtv
      @KDABtv  3 ปีที่แล้ว

      Hi Karl!
      We are very sorry to disappoint you but, unfortunately, we cannot share this talk’s slides from QtDay Italy 20 due to it being a longer workshop that directly overlaps with one of our training offers. If you are interested, we can forward you more information about said training.