Use QSignalMapper.
// create buttons
connect( b1, SIGNAL(clicked()), sm, SLOT(map()) );
...
// set mapping
sm->setMapping( b1, "A" );
...
connect( sm,
SIGNAL(mapped
(QString)),
this,
SLOT(keyboard
(QString)) );
slot keyboard
( const QString &key
) {
// do something with key
...
// restart timer
...
}
QSignalMapper *sm = new QSignalMapper( this );
// create buttons
QPushButton *b1 = new QPushButton( "A", this );
connect( b1, SIGNAL(clicked()), sm, SLOT(map()) );
...
// set mapping
sm->setMapping( b1, "A" );
...
connect( sm, SIGNAL(mapped(QString)), this, SLOT(keyboard(QString)) );
slot keyboard( const QString &key )
{
// do something with key
...
// restart timer
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks