Results 1 to 3 of 3

Thread: Should Q_PROPERTY always be CONSTANT or NOTIFY?

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Should Q_PROPERTY always be CONSTANT or NOTIFY?

    Hi,

    I have a Q_PROPERTY like so:

    Qt Code:
    1. Q_PROPERTY(QString name READ name WRITE setName)
    To copy to clipboard, switch view to plain text mode 

    clazy warns that

    a non-CONSTANT Q_PROPERTY is missing a NOTIFY signal.
    https://github.com/KDE/clazy/blob/1....hout-notify.md


    Why is that? In my case it cant be CONSTANT because it has a WRITE setter. But it cant be NOTIFY either because there is no signal fired when it is set.
    I am rarely using Q_PROPERTY, so my best guess is it's not the right tool for the case I am describing. If so, why not?


    Qt doc (https://doc.qt.io/qt-6/properties.html) also has some examples that look just like mine.

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Should Q_PROPERTY always be CONSTANT or NOTIFY?

    According the qt doc you posted the notify signal is optional so you're good like that, that should be just a warning. If you want to ger rid of that warning, just add a notify signal, even if you dont need it

    Qt Code:
    1. Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    2.  
    3. // you have to declare the notify signal
    4. signals:
    5. void nameChanged(int newName);
    To copy to clipboard, switch view to plain text mode 
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

  3. The following user says thank you to john_god for this useful post:

    tuli (24th November 2022)

  4. #3
    Join Date
    Sep 2024
    Posts
    1
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Should Q_PROPERTY always be CONSTANT or NOTIFY?

    `Q_PROPERTY` may not be suitable if you don’t need change notifications (`NOTIFY`) or if your property isn't constant and doesn't fit the `CONSTANT` criteria. In such cases, use regular getter and setter methods instead.

    drift hunters

Similar Threads

  1. Can't get the notify signal in QML
    By iveus in forum Newbie
    Replies: 2
    Last Post: 8th February 2020, 11:43
  2. Replies: 9
    Last Post: 17th August 2015, 17:52
  3. Constant Grid
    By myzinsky in forum Qwt
    Replies: 4
    Last Post: 5th September 2012, 11:48
  4. linux usb notify
    By duckshine in forum General Programming
    Replies: 1
    Last Post: 27th May 2011, 10:16
  5. Qt web notify
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:24

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.