0
votes

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.

1
Shouldn't you simply do it in the repair() method you're calling?Gui13
Is the slot repair really in senderButton or in this (which type is Reflex) ?alexisdm
well i should have explained more better .. its not the repair method just a suck name choose its just a procedure.. and the repair is in this. Basicly a need something that waits 1 sec and than modify the senderButton.FaNaT

1 Answers

1
votes

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.