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. is making everything a QObject bad practice?
Qt 6.11 is out! See what's new in the release blog

is making everything a QObject bad practice?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 248 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.
  • M Offline
    M Offline
    Mbkerdellou
    wrote on last edited by
    #1

    I have a simple mvc architecture, is it bad to connect the model to the ui through signals/slots? Because I will have to make every model class inherit qobject and i feel that makes everything tightly coupled.

    JonBJ SGaistS 2 Replies Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Hi,
      This is a very general question and therefore hard to answer. Generally nothing is wrong with signal/slot connections. And if you want to display data from a model, you don’t have many other choices. Maybe expand more about your use case and your code.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      2
      • M Mbkerdellou

        I have a simple mvc architecture, is it bad to connect the model to the ui through signals/slots? Because I will have to make every model class inherit qobject and i feel that makes everything tightly coupled.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Mbkerdellou
        Yes, where you want signals/slots you will need QObject. Including everything model<->UI, that is normal and expected. All Qt models ultimately inherit from QAbstractItemModel, which is QObject, and you would be advised to make your models derive from QAbstractItemModel or one of its subclasses too, so you will get QObject and the MV signals anyway.

        Where you have other classes which do not need signals/slots or other QObject features do not inherit QObject just for the sake of it. As an example, all the Qt "utility" classes, e.g. QList, QVariant or QFileInfo, do not.

        1 Reply Last reply
        2
        • M Mbkerdellou

          I have a simple mvc architecture, is it bad to connect the model to the ui through signals/slots? Because I will have to make every model class inherit qobject and i feel that makes everything tightly coupled.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mbkerdellou Hi,

          As @Axel-Spoerl wrote, you're a bit light on details.

          From you description you seem to have a certain amount of data structure that you want to expose to views.

          One possible way to implement that without having to refactor everything and make them all QObject is to write your own model(s) that will act as wrapper around these structure. That way you can keep things separated.

          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
          1

          • Login

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