[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-bindings
Subject: Re: [Kde-bindings] Using Signals/Slots with String argument
From: Dimitar Dobrev <dpldobrev () yahoo ! com>
Date: 2013-10-29 12:51:24
Message-ID: 1383051084.11665.YahooMailNeo () web122404 ! mail ! ne1 ! yahoo ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
You can use QtCoreApplication.Invoke. About InvokeMethod
On Tuesday, October 29, 2013 2:46 PM, Mat Arge <argemat1010@gmail.com> wrote:
What I acutally want to achieve, is to change the UI from a different thread.
According to the www, executing code in the UI thread can either be achieved
via QMetaObject.InvokeMethod (see my other message to the list today) or via a
signal/slot combination and so far I haven't managed to make either of them
work in Qyoto.
cheers
Mat
On Tuesday 29. October 2013 05:42:01 Dimitar Dobrev wrote:
> Hello, Mat,
>
> I don't know if adding slots as string has ever worked (it's not me who
> authored that part), I've never tried it. But let me ask you, why do you
> need it? Why don't you simply use the events that wrap signals? In your
> case that would be:
>
> dialogB1.Clicked += OnDialogIntClicked;
>
>
> About custom signals, it's analogous: I haven't tried them (and
> therefore I don't know if they've ever worked) but you can simply use
> Mono/.NET events instead.
>
> Regards,
> Dimitar
>
>
>
>
> On Tuesday, October 29, 2013 2:32 PM, Mat Arge <argemat1010@gmail.com>
> wrote:
>
> 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[],Sys
> tem.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
> _______________________________________________
> Kde-bindings mailing list
> Kde-bindings@kde.org
> https://mail.kde.org/mailman/listinfo/kde-bindings
_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
and slots as strings, I will only make sure they work with in the new Qyoto version.
Dimitar
[Attachment #5 (text/html)]
<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica \
Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><span \
class="tab"> You can use QtCoreApplication.Invoke. About </span>InvokeMethod \
<div style="display: block;" class="yahoo_quoted"> <br> <br> <div style="font-family: \
HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> \
<div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, \
sans-serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> On Tuesday, October \
29, 2013 2:46 PM, Mat Arge <argemat1010@gmail.com> wrote:<br> </font> </div> <div \
class="y_msg_container">What I acutally want to achieve, is to change the UI from a different \
thread. <br clear="none">According to the www, executing code in the UI thread can either be \
achieved <br clear="none">via QMetaObject.InvokeMethod (see my other message to the list \
today) or via a <br clear="none">signal/slot combination and so far I haven't managed to make \
either of them <br clear="none">work in Qyoto.<br clear="none"><br clear="none">cheers<br \
clear="none">Mat<br clear="none"><div class="yqt6454186082" id="yqtfd98996"><br clear="none">On \
Tuesday 29. October 2013 05:42:01 Dimitar Dobrev wrote:<br clear="none">> \
Hello, Mat,<br clear="none">> <br clear="none">> I don't know if adding \
slots as string has ever worked (it's not me who<br clear="none">> authored that part), I've \
never tried it. But let me ask you, why do you<br clear="none">> need it? Why don't you \
simply use the events that wrap signals? In your<br clear="none">> case that would be:<br \
clear="none">> <br clear="none">> dialogB1.Clicked += \
OnDialogIntClicked;<br clear="none">> <br clear="none">> <br clear="none">> \
About custom signals, it's analogous: I haven't tried them (and<br clear="none">> \
therefore I don't know if they've ever worked) but you can simply use<br clear="none">> \
Mono/.NET events instead.<br clear="none">> <br clear="none">> Regards,<br \
clear="none">> Dimitar<br clear="none">> <br clear="none">> <br \
clear="none">> <br clear="none">> <br clear="none">> On Tuesday, October 29, 2013 2:32 \
PM, Mat Arge <<a shape="rect" ymailto="mailto:argemat1010@gmail.com" \
href="mailto:argemat1010@gmail.com">argemat1010@gmail.com</a>><br clear="none">> \
wrote:<br clear="none">> <br clear="none">> Hy!<br clear="none">> <br \
clear="none">> I am unable to use signals/slots which use String as an argument. I \
created<br clear="none">> the code below to watch the value of a QInputDialog, If I set its \
InputMode<br clear="none">> to IntINput, everything works fine. But if I use the TextInput \
InputMode I<br clear="none">> get the error message<br clear="none">> QSignalSpy: No \
such signal: 'textValueChanged(string)'<br clear="none">> <br clear="none">> Even worse, \
if I try to define my own signal MySignal which uses a string<br clear="none">> argument, \
once I emit it I first get the error<br clear="none">> <br clear="none">> Cannot handle \
'string' as slot argument<br clear="none">> <br clear="none">> promptly followed by a \
stacktrace, followed by a native stacktrace:<br clear="none">> Stacktrace:<br \
clear="none">> <br clear="none">> at (wrapper managed-to-native) \
QtCore.SignalInvocation.SignalEmit<br clear="none">> (string,string,intptr,intptr,int) \
<0xffffffff><br clear="none">> at QtCore.SignalInvocation.Invoke<br \
clear="none">> (System.Runtime.Remoting.Messaging.IMessage) <0x002af><br \
clear="none">> at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke<br \
clear="none">> (System.Runtime.Remoting.Proxies.RealProxy,System.Runtime.Remoting.Messaging<br \
clear="none">> .IMessage,System.Exception&,object[]&) <0x003e3><br \
clear="none">> at (wrapper runtime-invoke)<br clear="none">> \
<Module>.runtime_invoke_object_object_object_Exception&_object[]&<br \
clear="none">> (object,intptr,intptr,intptr) <0xffffffff><br clear="none">> \
at (wrapper managed-to-native)<br clear="none">> \
object.__icall_wrapper_mono_remoting_wrapper (intptr,intptr) <0xffffffff><br \
clear="none">> at (wrapper remoting-invoke) IMySignals.MySignal (string) \
<0xffffffff><br clear="none">> at Dialog.<Dialog>m__1 () \
<0x000d2><br clear="none">> at (wrapper runtime-invoke) \
object.runtime_invoke_void__this__<br clear="none">> (object,intptr,intptr,intptr) \
<0xffffffff><br clear="none">> at (wrapper managed-to-native) \
System.Reflection.MonoMethod.InternalInvoke<br clear="none">> \
(System.Reflection.MonoMethod,object,object[],System.Exception&)<br clear="none">> \
<0xffffffff> at System.Reflection.MonoMethod.Invoke<br clear="none">> \
(object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],Sys<br \
clear="none">> tem.Globalization.CultureInfo) <0x0013f><br clear="none">> at \
System.Reflection.MethodBase.Invoke (object,object[]) <0x00022><br \
clear="none">> at System.Delegate.DynamicInvokeImpl (object[]) <0x001bf><br \
clear="none">> at System.MulticastDelegate.DynamicInvokeImpl (object[]) \
<0x00033><br clear="none">> at System.Delegate.DynamicInvoke (object[]) \
<0x00016><br clear="none">> at QtCore.SmokeInvocation.InvokeDelegate \
(System.Delegate,intptr)<br clear="none">> <0x000bf> at (wrapper native-to-managed)<br \
clear="none">> QtCore.SmokeInvocation.InvokeDelegate (System.Delegate,intptr) \
<0xffffffff><br clear="none">> at (wrapper managed-to-native) \
QtCore.SmokeInvocation.CallSmokeMethod<br clear="none">> \
(intptr,int,intptr,intptr,int,intptr) <0xffffffff><br clear="none">> at \
QtCore.SmokeInvocation.Invoke (string,string,System.Type,bool,object[])<br clear="none">> \
<0x00277><br clear="none">> at QtGui.QApplication.Exec () <0x00047><br \
clear="none">> at Dialog.Main (string[]) <0x00047><br clear="none">> \
at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object<br clear="none">> \
(object,intptr,intptr,intptr) <0xffffffff><br clear="none">> <br clear="none">> \
Native stacktrace:<br clear="none">> <br clear="none">> \
mono() [0x80e903d]<br clear="none">> \
linux-gate.so.1(__kernel_rt_sigreturn+0) [0xb772b410]<br clear="none">> ...<br \
clear="none">> <br clear="none">> Here is my sample code:<br clear="none">> <br \
clear="none">> using System;<br clear="none">> using QtCore;<br clear="none">> using \
QtGui;<br clear="none">> <br clear="none">> public class Dialog : QWidget<br \
clear="none">> {<br clear="none">> int width = 250;<br clear="none">> \
int height = 200;<br clear="none">> <br clear="none">> <br clear="none">> \
public Dialog()<br clear="none">> {<br clear="none">> WindowTitle = \
"Input test";<br clear="none">> <br clear="none">> Resize(width, \
height);<br clear="none">> <br clear="none">> var vbox = new \
QVBoxLayout(this);<br clear="none">> QPushButton quit = new \
QPushButton("Quit");<br clear="none">> Connect(quit, SIGNAL("clicked()"), () \
=> QCoreApplication.Quit());<br clear="none">> vbox.AddWidget(quit);<br \
clear="none">> <br clear="none">> QPushButton dialogB1 = new \
QPushButton("Dialog Int");<br clear="none">> Connect(dialogB1, \
SIGNAL("clicked()"), this,<br clear="none">> SLOT("OnDialogIntClicked()"));<br \
clear="none">> vbox.AddWidget(dialogB1);<br clear="none">> <br \
clear="none">> QPushButton dialogB2 = new QPushButton("Dialog Text");<br \
clear="none">> Connect(dialogB2, SIGNAL("clicked()"), this,<br \
clear="none">> SLOT("OnDialogTextClicked()"));<br clear="none">> \
vbox.AddWidget(dialogB2);<br clear="none">> <br clear="none">> \
QPushButton mySig = new QPushButton("MySignal");<br clear="none">> \
Connect(mySig, SIGNAL("clicked()"), () => {Emit.MySignal("Signal emitted<br \
clear="none">> at "+DateTime.Now);});<br clear="none">> \
vbox.AddWidget(mySig);<br clear="none">> <br clear="none">> \
Show();<br clear="none">> }<br clear="none">> <br clear="none">> \
[Q_SLOT]<br clear="none">> public void OnDialogIntClicked()<br \
clear="none">> {<br clear="none">> var dialog = new \
QInputDialog(this);<br clear="none">> dialog.inputMode = \
QInputDialog.InputMode.IntInput;<br clear="none">> dialog.Open();<br \
clear="none">> Connect(dialog, \
SIGNAL("intValueChanged(int)"), (int i) =><br clear="none">> {Console.WriteLine("New Int \
value: '{0}'", i);});<br clear="none">> }<br clear="none">> <br \
clear="none">> [Q_SLOT]<br clear="none">> public void \
OnDialogTextClicked()<br clear="none">> {<br clear="none">> \
var dialog = new QInputDialog(this);<br clear="none">> \
dialog.inputMode = QInputDialog.InputMode.TextInput;<br clear="none">> \
dialog.Open();<br clear="none">> Connect(dialog, \
SIGNAL("textValueChanged(string)"), (string s) =><br clear="none">> \
{Console.WriteLine("New Text value: '{0}'", s);});<br clear="none">> }<br \
clear="none">> <br clear="none">> protected new IMySignals Emit {<br \
clear="none">> get {<br clear="none">> return \
(IMySignals) Q_EMIT;<br clear="none">> }<br clear="none">> }<br \
clear="none">> <br clear="none">> <br clear="none">> [STAThread]<br \
clear="none">> public static int Main(string[] args)<br \
clear="none">> {<br clear="none">> new \
QApplication(args);<br clear="none">> var app = new Dialog();<br \
clear="none">> return QApplication.Exec();<br \
clear="none">> }<br clear="none">> }<br clear="none">> <br \
clear="none">> public interface IMySignals : IQWidgetSignals {<br clear="none">> \
[Q_SIGNAL("mySignal(string)")]<br clear="none">> \
void MySignal(string val);<br clear="none">> }<br clear="none">> <br \
clear="none">> <br clear="none">> cheers<br clear="none">> Mat<br clear="none">> \
_______________________________________________<br clear="none">> Kde-bindings mailing \
list<br clear="none">> <a shape="rect" ymailto="mailto:Kde-bindings@kde.org" \
href="mailto:Kde-bindings@kde.org">Kde-bindings@kde.org</a><br clear="none">> <a \
shape="rect" href="https://mail.kde.org/mailman/listinfo/kde-bindings" \
target="_blank">https://mail.kde.org/mailman/listinfo/kde-bindings</a><br \
clear="none"></div><br><div class="yqt6454186082" \
id="yqtfd28258">_______________________________________________<br clear="none">Kde-bindings \
mailing list<br clear="none"><a shape="rect" ymailto="mailto:Kde-bindings@kde.org" \
href="mailto:Kde-bindings@kde.org">Kde-bindings@kde.org</a><br clear="none"><a shape="rect" \
href="https://mail.kde.org/mailman/listinfo/kde-bindings" \
target="_blank">https://mail.kde.org/mailman/listinfo/kde-bindings</a><br \
clear="none"></div><br><br></div> </div> </div> </div> and slots as strings, I will only make \
sure they work with in the new Qyoto version.<br><br><span class="tab"> \
Dimitar</span><br></div></body></html>
_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic