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. QObject with property-like members: use owning class for signals/slots

QObject with property-like members: use owning class for signals/slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 276 Views 1 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.
  • T Offline
    T Offline
    target-san
    wrote on last edited by
    #1

    Hello!

    Use of signal/slot system requires type to descend from QObject and have Q_OBJECT macro as part of its declaration in order for QtMOC to process it. And the recommended way to implement object's properties is to implement accessor methods and signals by hand.

    Although, this causes a lot of boilerplate in my case where I have multiple properties with almost identical logic, and kind of pollution of class scope. So I wondered if I can define "property" class which is always a member of certain QObject-derived class and has its own set of methods and signals. And consequently have not

    someobject.setProperty(...);
    // ...
    emit someobject.propertyChanged(...);
    

    but

    someobject.property.set(...);
    // ...
    emit someobject.property.changed(...);
    

    This is definitely doable if I derive my property class from QObject. Although this looks a bit redundant since property instance does not exist apart from its containing object.

    So my question is. Is there some way to tell Qt to implement signal/slot bindings for certain type through its mandatory owner type?

    Thanks

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

      Hi,

      If you have properties that a repeating but changing only in implementation, why not have a base class which defines them and then use subclasses where you implement the methods that are different ?

      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
      2

      • Login

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