Search code examples
c++qtsignals-slotsvariantqtwidgets

QT: Connect a signal with a fundamental type in its signature to a slot with QVariant in its signature


I'd like to connect a signal with one parameter of a fundamental type like

void toggled(bool checked)
void valueChanged(int i)
...

to a slot with its parameter being of type QVariant:

void setValue( QVariant &value )

Is that possible using Qt 5.14 ?


Solution

  • You can as long as you change

    void setValue(QVariant & value)
    

    into

    void setValue(QVariant value)
    

    or

    void setValue(const QVariant & value)
    

    otherwise compilation will fail with a static assertion failed (Signal and slot arguments are not compatible).