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. Deactivate checked Checkbox if a certain condition is met?

Deactivate checked Checkbox if a certain condition is met?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.0k Views
  • 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've got a qml-checkbox connected to a cpp-class like this:

    @CheckBox {
    id: check
    checked: cppInterface.checker
    onCheckedChanged: cppInterface.setChecker(check.checked,true)
    }@

    When it's checked or unchecked setChecker is executed.
    In setChecker I check if the Checkbox was activated, if yes, I check further if the condition is met.
    If not I want to uncheck the CheckBox again using setchecker. That doesn't work for some reasons.

    It is connected to C++ like this:

    @Q_PROPERTY(bool checker READ isChecker WRITE setChecker NOTIFY checkerChanged)
    public:
    bool isChecker()
    Q_INVOKABLE void setChecker(bool value, bool emitSignal);
    signals:
    void checkerChanged();
    private:
    m_checker;@

    setChecker is looking like this:

    @void QmlCppMediator::setChecker(bool value, bool emitSignal){
    m_checked = value;

    if (emitSignal){
    emit checkerChanged();
    }

    }@

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      If it works as it is, it would go in to infinite loop.. May be it being detected by compiler and disallowed it.

      And one more thing is that setChecker function should take only one argument that is bool ( it is a setter function for m_checker ). Can you make one more function to make call from QML to CPP, and not mix it work setChecker.

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

        Normally you'd be right but QML seems to be intelligent about these loops. It gives a warning but doesn't actually go into that loop.

        I tried everything you said, simplyfying the example more and more. While I can change the checked state of that component I could never change it visually.

        That's why I reported it as a bug here:

        "Your text to link here...":http://bugreports.qt.nokia.com/browse/QTCOMPONENTS-910

        1 Reply Last reply
        0
        • N Offline
          N Offline
          njeisecke
          wrote on last edited by
          #4

          Boilerplate code for setters looks like this:

          @
          void QmlCppMediator::setChecker(bool value)
          {
          if (m_checked == value)
          return;

          m_checked = value;
          emit checkerChanged();
          }
          @

          With this code, Qml and C++ should always be in sync.

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

            Thanks, I tried this as well.
            It seems like a bug in the implementation of QDesktop's CheckBox. Reported it.

            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