FaNaT
FaNaT

Reputation: 246

QTimer singleShot use the activator

My problem is the following: I have QPushbutton* that calls this

void Reflex::buttonClicked(){

QObject* senderObject = sender();
QPushButton* senderButton = qobject_cast<QPushButton*>(senderObject);
if (senderButton->text() == " "){
    .
    .
    .
    QTimer::singleShot(1000, senderButton, SLOT(repair()));
}

And when the singleshot proc i want to make some changes on the senderButton but i cant figure out how should i do it.

Upvotes: 0

Views: 567

Answers (1)

David D
David D

Reputation: 1591

Possibilities:

1) (This option is more OO, and much more sane to maintain) Subclass QButton to have a signal that looks something like this:

void delayedClick(QPushButton *);

Now, override void QPushButton::mousePressEvent ( QMouseEvent * e ) [virtual protected] and have it start a timer to emit the delayedCLick signal on timeout.

Finally, connect this to whatever cares about the button, and you're done.

2) (Using what you've got) Using what you've shown us so far, you could just save the clicked button as a member variable (in Reflex) and reference it in react to perform your tasks.

Note from the QT docs: Warning: This function [sender()] violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.

IE: AVOID if possible. It is pretty easy to do the subclassing.

Upvotes: 1

Related Questions