Hello friends,
is it possible to expose qvariant datatype to qml or vice versa?
Hello friends,
is it possible to expose qvariant datatype to qml or vice versa?
Yes.
If you have a fixed value, you can set it as a context property.
If it is a changing value, you will need a QObject subclass and a Q_PROPERTY with type QVariant and then set an instance of that class as a context property.
Cheers,
_
Isn't it a little bit overhead. I just want return a value of a method which is a member of a cpp class.
Imagine following sample:
var result = cppobject.method ();
You can do that as well.
Qt Code:
{ Q_OBJECT public: };To copy to clipboard, switch view to plain text mode
Cheers,
_
Thank you for your suggestions, but it does not compile.
it says: Error: C2079: '_r' uses undefined class 'QVariant'
Error: C2027: use of undefined type 'QVariant'
I add QT += core and #include the relevant <QVariant> but nothing helps. How do I schould implement the function?
I do a simple stuff to test the exposing through qml:
QVariant SomeClass::method(){
QVariant var(123);
return var;
}
QT += core is not necessary, that is implied by any other Qt module.
Undefined type usually means that the include is missing.
Maybe you added the include to the wrong file?
For which file do you get the error?
Or maybe forgot the forward declaration in the header of SomeClass?
Can you post header and source for SomeClass?
Cheers,
_
Bookmarks