Unsolved Can I get the real type of QVariant params?
-
I want to send a QVariant param (event it's a struct) by a signal, also when it is sent to a slot by a signal, the slot can get the type from this param. How can I achieve.
I have a fool idea that I add a QString to descript the type, or use an enum of type.
Could you give me some suggestions? -
Register your cutom type with the Meta-Object system using https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1, save the return integer then you can use
QVariant::userType()
to check if the variant contains your custom type or not -
Oh, thank you so much !
BTW, can I connect a normal signal of a widget and a slot with a QVariant param? -
@Mihan said in Can I get the real type of QVariant params?:
BTW, can I connect a normal signal of a widget and a slot with a QVariant param?
Sure you can.
connect(myclass, &MyClass::mySignal, this, &QMainWindow::DoSomething);
where
mySignal
void mySignal(QVariant val);
and
DoSomething
slot:void QMainWindow::DoSomething(QVariant val) { // Do something with Variant val }