Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] Preventing binding-loops is inconvenient
Qt 6.11 is out! See what's new in the release blog

[solved] Preventing binding-loops is inconvenient

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 3.2k 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.
  • H Offline
    H Offline
    Hedge
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hedge
        wrote on last edited by
        #3

        Thank you.

        That is a much smarter way of handling it.

        Congratulations to your 1000th post as well.

        1 Reply Last reply
        0

        • Login

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