2

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 ?

Lars Hadidi
  • 558
  • 1
  • 5
  • 15

2 Answers2

2

Yes, you can connect signals to slots as long as there is an implicit conversion from the signal parameter to the slot parameter.

Given that Qvariant has constructors from int and bool, these constructors will be used to perform the implicit conversion.

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
1

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).

p-a-o-l-o
  • 9,807
  • 2
  • 22
  • 35