qconnect: Connect a signal handler

Description Usage Arguments Details Value Author(s) Examples

View source: R/connect.R

Description

Like many other GUI toolkits, Qt supports connecting handler functions to signals, which are emitted in response to user actions. The qconnect function connects an R function to a signal on a Qt object.

Usage

1
qconnect(x, signal, handler, user.data)

Arguments

x

The Qt object providing the signal

signal

The name of the signal

handler

The R function to handle the signal

user.data

Data to pass to the R function as the last parameter. If omitted, no such argument is passed to the handler.

Details

In Qt, only other QObject instances can listen to a signal, so this function creates a dummy object that invokes the R function upon receipt of the signal.

To disconnect a handler, call the disconnect method on the signal emitter x, passing it the returned dummy QObject; see the example.

Value

A dummy QObject instance that is listening to the signal. Will become invalid when the signal emitter is invalidated.

Author(s)

Michael Lawrence

Examples

1
2
3
4
window <- Qt$QWidget()
button <- Qt$QPushButton(window)
listener <- qconnect(button, "pressed", function(x) print("hello world"))
button$disconnect(listener)

qtbase documentation built on May 2, 2019, 9:58 a.m.