[solved] Preventing binding-loops is inconvenient



  • I'm building a desktop-application with Qt and I may overlook something but that's how I prevent binding-loops.
    Let's take an editable TextField for example:

    @ TextField {
    id: twitterCustomMessage
    enabled: cppInterface.twitterConnected
    text: cppInterface.twitterCustomMessage
    onTextChanged: cppInterface.setTwitterCustomMessage(twitterCustomMessage.text,false)
    width: 200
    }@

    I need to bind it's text-attribute to an actual Q_PROPERTY. To be able to react upon the user entering text I have to link onTextChanged to an INVOKABLE method. Here I use the set-method of the Q_PROPERTY which looks like this:

    @void QmlCppMediator::setTwitterCustomMessage(QString value, bool emitSignal){
    m_twitterCustomMessage = value;

    if (emitSignal){
        emit twitterCustomMessageChanged();
    }
    else {
        emit twitterCustomMessageSaveSignal();
    }
    

    }@

    I had to add the seconds parameter so it wouldn't cause a binding-loop. I also had to add another signal I can connect to a slot of the parent-class of the whole qml-cpp-mediator thing.

    The easier method would be having another method emitting twitterCustomMessageSaveSignal but this is still a lot.

    Does anyone have suggestion to simplify this process?


  • Moderators

    http://developer.qt.nokia.com/forums/viewthread/1779/ claims that doing the setter method properly will stop the warning.



  • Thank you.

    That is a much smarter way of handling it.

    Congratulations to your 1000th post as well.


Log in to reply
 

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