[Qt-interest] Calling a QML-method within C++-code

Thiago Macieira thiago at kde.org
Tue Apr 5 00:30:42 CEST 2011


On Tuesday, 5 de April de 2011 00:02:34 Hendrik vP wrote:
> i tried to change the declaration of my qvariant-variable. It turned out,
> that QVariant(QMetaType::QObjectStar, object) is insufficient and
> unnecessary - the way to go is
> QVariant wrapped;
> wrapped.setValue<QObject*>(object);
> I don't understand how and why this works and the other declaration
> not - maybe someone can brighten this thing up. But at least, it works
> now.

When in doubt, try a different type. Let's take for example an int:

	int i = 42;
	QVariant(QVariant::Int, i);

Result: compilation error. QVariant takes a void *. So we do:

	int i = 42;
	QVariant(QVariant::Int, &i);

and this works. Now apply the same for a QObejct* and QMetaType::QObjectStar.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110404/61a349d3/attachment.bin 


More information about the Qt-interest-old mailing list