[Kde-bindings] Using Signals/Slots with String argument
Mat Arge
argemat1010 at gmail.com
Tue Oct 29 12:32:18 UTC 2013
Hy!
I am unable to use signals/slots which use String as an argument. I created
the code below to watch the value of a QInputDialog, If I set its InputMode to
IntINput, everything works fine. But if I use the TextInput InputMode I get
the error message
QSignalSpy: No such signal: 'textValueChanged(string)'
Even worse, if I try to define my own signal MySignal which uses a string
argument, once I emit it I first get the error
Cannot handle 'string' as slot argument
promptly followed by a stacktrace, followed by a native stacktrace:
Stacktrace:
at (wrapper managed-to-native) QtCore.SignalInvocation.SignalEmit
(string,string,intptr,intptr,int) <0xffffffff>
at QtCore.SignalInvocation.Invoke
(System.Runtime.Remoting.Messaging.IMessage) <0x002af>
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke
(System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging.IMessage,System.Exception&,object[]&)
<0x003e3>
at (wrapper runtime-invoke)
<Module>.runtime_invoke_object_object_object_Exception&_object[]&
(object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_remoting_wrapper
(intptr,intptr) <0xffffffff>
at (wrapper remoting-invoke) IMySignals.MySignal (string) <0xffffffff>
at Dialog.<Dialog>m__1 () <0x000d2>
at (wrapper runtime-invoke) object.runtime_invoke_void__this__
(object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&) <0xffffffff>
at System.Reflection.MonoMethod.Invoke
(object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo)
<0x0013f>
at System.Reflection.MethodBase.Invoke (object,object[]) <0x00022>
at System.Delegate.DynamicInvokeImpl (object[]) <0x001bf>
at System.MulticastDelegate.DynamicInvokeImpl (object[]) <0x00033>
at System.Delegate.DynamicInvoke (object[]) <0x00016>
at QtCore.SmokeInvocation.InvokeDelegate (System.Delegate,intptr) <0x000bf>
at (wrapper native-to-managed) QtCore.SmokeInvocation.InvokeDelegate
(System.Delegate,intptr) <0xffffffff>
at (wrapper managed-to-native) QtCore.SmokeInvocation.CallSmokeMethod
(intptr,int,intptr,intptr,int,intptr) <0xffffffff>
at QtCore.SmokeInvocation.Invoke (string,string,System.Type,bool,object[])
<0x00277>
at QtGui.QApplication.Exec () <0x00047>
at Dialog.Main (string[]) <0x00047>
at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object
(object,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
mono() [0x80e903d]
linux-gate.so.1(__kernel_rt_sigreturn+0) [0xb772b410]
...
Here is my sample code:
using System;
using QtCore;
using QtGui;
public class Dialog : QWidget
{
int width = 250;
int height = 200;
public Dialog()
{
WindowTitle = "Input test";
Resize(width, height);
var vbox = new QVBoxLayout(this);
QPushButton quit = new QPushButton("Quit");
Connect(quit, SIGNAL("clicked()"), () => QCoreApplication.Quit());
vbox.AddWidget(quit);
QPushButton dialogB1 = new QPushButton("Dialog Int");
Connect(dialogB1, SIGNAL("clicked()"), this,
SLOT("OnDialogIntClicked()"));
vbox.AddWidget(dialogB1);
QPushButton dialogB2 = new QPushButton("Dialog Text");
Connect(dialogB2, SIGNAL("clicked()"), this,
SLOT("OnDialogTextClicked()"));
vbox.AddWidget(dialogB2);
QPushButton mySig = new QPushButton("MySignal");
Connect(mySig, SIGNAL("clicked()"), () => {Emit.MySignal("Signal emitted
at "+DateTime.Now);});
vbox.AddWidget(mySig);
Show();
}
[Q_SLOT]
public void OnDialogIntClicked()
{
var dialog = new QInputDialog(this);
dialog.inputMode = QInputDialog.InputMode.IntInput;
dialog.Open();
Connect(dialog, SIGNAL("intValueChanged(int)"), (int i) =>
{Console.WriteLine("New Int value: '{0}'", i);});
}
[Q_SLOT]
public void OnDialogTextClicked()
{
var dialog = new QInputDialog(this);
dialog.inputMode = QInputDialog.InputMode.TextInput;
dialog.Open();
Connect(dialog, SIGNAL("textValueChanged(string)"), (string s) =>
{Console.WriteLine("New Text value: '{0}'", s);});
}
protected new IMySignals Emit {
get {
return (IMySignals) Q_EMIT;
}
}
[STAThread]
public static int Main(string[] args)
{
new QApplication(args);
var app = new Dialog();
return QApplication.Exec();
}
}
public interface IMySignals : IQWidgetSignals {
[Q_SIGNAL("mySignal(string)")]
void MySignal(string val);
}
cheers
Mat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 665 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20131029/d3c59245/attachment.sig>
More information about the Kde-bindings
mailing list