Please nominate your Qt Champions for 2021!

event connect not honoring default value of handler

  • 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?

  • @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.

Log in to reply