ddobrev / QtSharp

Mono/.NET bindings for Qt
Other
571 stars 52 forks source link

QML Invoke won´t work #55

Open bjoernrennfanz opened 7 years ago

bjoernrennfanz commented 7 years ago

Hello,

i tried to call a QML function from C#. I have implemented a simple sample form QT See ref: http://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

But it does not work. Here is my code...

QQmlEngine engine = new QQmlEngine();
QQmlComponent component = new QQmlComponent(engine, QUrl.FromLocalFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "myitem.qml")));
QObject test1 = component.Create();

QVariant msg = "Hello from C++";
QVariant returnedValue = new QVariant();
bool test = QMetaObject.InvokeMethod(test1, "myQmlFunction", new QGenericReturnArgument("QVariant", returnedValue.Data) , new QGenericArgument("QVariant", msg.Data));

Console.Write(returnedValue.ToString());

The InvokeMethod always returns with "false". Have anybody a idea what is wrong?