[GH-ISSUE #138] How to invoke C++ method? #86

Closed
opened 2026-05-05 11:03:57 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @vadi2 on GitHub (May 24, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/138

I see that it's possible to invoke a C++ method from the readme, but I can't get it working. My example:

// QML
TextArea {
  id: textArea
  Component.onCompleted: dotnet.invokeCpp(textArea)
}

// C#
    public void InvokeCpp(dynamic qQuickTextDocument)
    {
      var qTextDocument = qQuickTextDocument.textDocument();
    }

It just bombs out with:

Exception has occurred: CLR/System.Exception
An unhandled exception of type 'System.Exception' occurred in Qml.Net.dll: 'Invoking method failed.'
   at Qml.Net.Internal.Qml.NetQObject.InvokeMethod(String methodName, NetVariantList parameters)
   at Qml.Net.Internal.Qml.NetQObject.NetQObjectDynamic.InvokeMethod(String methodName, Object[] parameters)
   at Qml.Net.Internal.Qml.NetQObject.NetQObjectDynamic.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
   at Program.NetObject.InvokeCpp(Object qQuickTextDocument) in /home/vadi/Programs/Hammer/Program.cs:line 156

I've verified that I am indeed passing in a QQuickTextDocument class which has a QTextDocument * textDocument() const method.

Originally created by @vadi2 on GitHub (May 24, 2019). Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/138 I see that it's possible to invoke a C++ method from the readme, but I can't get it working. My example: ```js // QML TextArea { id: textArea Component.onCompleted: dotnet.invokeCpp(textArea) } // C# public void InvokeCpp(dynamic qQuickTextDocument) { var qTextDocument = qQuickTextDocument.textDocument(); } ``` It just bombs out with: ``` Exception has occurred: CLR/System.Exception An unhandled exception of type 'System.Exception' occurred in Qml.Net.dll: 'Invoking method failed.' at Qml.Net.Internal.Qml.NetQObject.InvokeMethod(String methodName, NetVariantList parameters) at Qml.Net.Internal.Qml.NetQObject.NetQObjectDynamic.InvokeMethod(String methodName, Object[] parameters) at Qml.Net.Internal.Qml.NetQObject.NetQObjectDynamic.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at Program.NetObject.InvokeCpp(Object qQuickTextDocument) in /home/vadi/Programs/Hammer/Program.cs:line 156 ``` I've verified that I am indeed passing in a `QQuickTextDocument` class which has a `QTextDocument * textDocument() const` method.
Author
Owner

@vadi2 commented on GitHub (May 28, 2019):

I've tried a whole lot of things involving InvokeMethod but nothing is working.

<!-- gh-comment-id:496615617 --> @vadi2 commented on GitHub (May 28, 2019): I've tried a whole lot of things involving `InvokeMethod` but nothing is working.
Author
Owner

@iWeaverMan commented on GitHub (May 29, 2019):

Method textDocument() is not invokable
https://stackoverflow.com/questions/24642370/qmetaobjectinvokemethod-no-such-method-when-using-inheritance/24642620

<!-- gh-comment-id:496816419 --> @iWeaverMan commented on GitHub (May 29, 2019): Method textDocument() is not invokable https://stackoverflow.com/questions/24642370/qmetaobjectinvokemethod-no-such-method-when-using-inheritance/24642620
Author
Owner

@vadi2 commented on GitHub (May 29, 2019):

Oh. So Qml.Net can't actually invoke any method? What can I do then - do I have to provide some C++ glue myself?

<!-- gh-comment-id:496819575 --> @vadi2 commented on GitHub (May 29, 2019): Oh. So Qml.Net can't actually invoke any method? What can I do then - do I have to provide some C++ glue myself?
Author
Owner

@pauldotknopf commented on GitHub (Jun 10, 2019):

You'd have to provide C++ glue yourself.

You can only invoke things that are known to the Qt meta system.

<!-- gh-comment-id:500268144 --> @pauldotknopf commented on GitHub (Jun 10, 2019): You'd have to provide C++ glue yourself. You can only invoke things that are known to the Qt meta system.
Author
Owner

@pauldotknopf commented on GitHub (Jul 9, 2019):

Update, you can interact with QObject`` types now using INetQObject```.

<!-- gh-comment-id:509557749 --> @pauldotknopf commented on GitHub (Jul 9, 2019): Update, you can interact with ```QObject`` types now using ```INetQObject```.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/qmlnet#86
No description provided.