qtbase (version 1.1.0)

qconnect: Connect a signal handler

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

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.

Value

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

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.

Examples

Run this code
window <- Qt$QWidget()
button <- Qt$QPushButton(window)
listener <- qconnect(button, "pressed", function(x) print("hello world"))
button$disconnect(listener)

Run the code above in your browser using DataCamp Workspace