<SOLVED>Qt Property System



  • Hi
    I have been reading about Qt's property system, in particular the NOTIFY optional specifier.
    Can NOTIFY be used with non Qml/QtQuick applications?

    Thanks



  • Yes, it can be accessed through qt meta system

    @
    QMetaMethod QMetaProperty::notifySignal() const
    @



  • Hi
    Thanks for your reply.
    I am having some issues with getting this to work
    in my class declaration I have
    @
    Q_PROPERTY (bool running READ running WRITE setRunning NOTIFY runningChanged)
    .
    .
    .
    private slots:
    void onRunningChanged();
    signals:
    void runningChanged();

    @

    In another class I have
    @
    connect(m_currentSession,&Session::runningChanged,this,&Manager::onRunningChanged);
    @

    But when the property changes my slot is not called

    Am I misunderstanding how it is supposed to work?

    Thanks


  • Moderators

    You need to emit the signal yourself in your C++ code.



  • Hi, these has nothing to do with the macro Q_PROPERTY.

    You should always emit the the signal runningChanged by yourself when the property changed, for exmple, in your setRunning() function.


  • Lifetime Qt Champion

    Hi,

    To add to my fellows, the standard construct is:

    @
    void setMyProperty(int value) {
    if (_myProperty != value) {
    _myProperty = value;
    // start some really cool stuff
    emit myPropertyChanged(_myProperty)
    }
    }
    @

    But it's not the only one possible


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.