Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved event connect not honoring default value of handler

    General and Desktop
    2
    2
    69
    Loading More Posts
    • 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.
    • R
      RobbieP last edited by

      I have a button that I have tied to an event that has a default value. like so:

      here's the event:

      connect(gaugeDivisions1SpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &Window::divisions1Changed);
      

      here's the slot definition:

      private slots:
          void divisions1Changed(bool color = false);
      

      and here's the actual event code:

      void Window::divisions1Changed(bool Color)
      {
          QColor pColor = Qt::black;
          if (Color) pColor = getColor();
          renderArea->setDivisions1(gaugeDivisions1SpinBox->value(), gaugeDivisions1InnerRadiusSpinBox->value(), gaugeDivisions1OuterRadiusSpinBox->value(), gaugeDivisions1WidthSpinBox->value(), pColor);
      }
      

      When I click the spinbox, the Color bool value comes across as true. but if I call the event otherwise with no parameter...Color is correctly assumed false. What am I doing wrong? Anyone have any ideas?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @RobbieP last edited by JonB

        @RobbieP said in event connect not honoring default value of handler:
        Signal void QSpinBox::valueChanged(int i) --- and your connect() to QOverload<int>::of(&QSpinBox::valueChanged) ---sends i as parameter, you let that through to your slot void divisions1Changed(bool color = false) as the value of color. Change your slot to match, or munch the i parameter in a lambda.

        1 Reply Last reply Reply Quote 2
        • First post
          Last post