<br><br><div class="gmail_quote">On Wed, Aug 11, 2010 at 9:13 AM, John Verzani <span dir="ltr">&lt;<a href="mailto:verzani@math.csi.cuny.edu">verzani@math.csi.cuny.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
 When defining classes and setting methods (qsetClass, qsetMethod) the environment has the object &quot;this&quot; and &quot;super&quot; available to it. Would this be possible within a callback set by qconnect? In RGtk2 and tcltk there is a way to get the object within the callback without having to use global variables or pass that object in through user.data.<br clear="all">

<br>E.g., something like this<br><br>b &lt;- Qt$QPushButton(&quot;click me&quot;)<br>qconnect(b, &quot;pressed&quot;, function(...) print(this$text))<br><br>It is easy enough to hack qconnect to add in &quot;this&quot; to the environment of the handler, but I&#39;m not sure how &quot;super&quot; would be done.<br>
<font color="#888888">
<br></font></blockquote><div><br><br>I agree that it would be convenient to have a pointer to the sender. I don&#39;t like the idea the idea of using &#39;this&#39; though. Usually, my signal handlers are a method in another class, so &#39;this&#39; would conflict. Also, conceptually it does not make sense, as the handler is usually not a method of the sender. Same with super. <br>
<br>The reason Qt does not pass the instance to the handler is that the handlers are methods that should be invokable even when there is no signal emission. Also, the handler is always a closure, with the enclosing &quot;environment&quot; being another instance that can easily hold a reference to the sender. This works well for me, although I can see that a simple Hello World application might run into some difficulties. Or cases where a slot is connected to many signals, but then the protected QObject::sender method is available for those using a class. Even then, many signals provide additional arguments that make the sender irrelevant.<br>
<br>We could add a &#39;sender&#39; variable to the enclosure. However, qtbase is in some ways extending the R language by adding the &#39;this&#39; and &#39;super&#39; keywords. If possible, we should limit the number of keywords. Also, an arbitrary R function is distinct from a method, which is by definition enclosed within an instance that essentially contains the &#39;this&#39; and &#39;super&#39; objects. I would rather not mess with the enclosing environment of a signal handler.<br>
<br>What if we tried to bring things back towards GTK+, C# events, etc, and just have the sender passed as the first argument? Obviously, we would not want this in many cases, so it would need to be an option that is off by default. <br>
<br>qconnect(b, &quot;pressed&quot;, function(x) print(x$text()), sender = TRUE)<br><br>Would this work?<br>Honestly, my original plan was just to have people use the user-data. If they need additional user-data, perhaps it is time to start thinking about a class.<br>
<br>Thanks,<br>Michael<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><font color="#888888">-- <br>John Verzani<br>Chair, Department of Mathematics<br>
College of Staten Island, CUNY<br><a href="mailto:verzani@math.csi.cuny.edu" target="_blank">verzani@math.csi.cuny.edu</a><br>
</font><br>_______________________________________________<br>
Qtinterfaces-devel mailing list<br>
<a href="mailto:Qtinterfaces-devel@lists.r-forge.r-project.org">Qtinterfaces-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/qtinterfaces-devel</a><br>
<br></blockquote></div><br>