I'm trying to keep track of which button(sender) is being clicked I tried using the QObject::sender() but that gives me weird numbers(ex: 0xb07f970) and not like an index
so then I tired this for my header:
Qt Code:
class: QPushButton; class: QGridLayout; private slots: private: QGridLayout *layout;To copy to clipboard, switch view to plain text mode
and on my c++
but the signal doesn't even seem to be sent to the timeButton_PressedQt Code:
class::class(){ for(int i = 0; i < 24; i++){ timeButton[i]->setText(inum); timeButtons->addButton(timeButton[i],i); layout->addWidget(timeButton[i]); connect(timeButton[i],SIGNAL(clicked()), } setLayout(layout); } cout << "SIGNAL BEING SENT" << endl; for(int i = 0;i<24;i++){ if(inum == timeButton[i]->text()){ cout << "button: " << i << " has been pressed!" << endl; } } //cout << "BUTTON " << QObject::sender() << " has been pressed" << endl; }To copy to clipboard, switch view to plain text mode
and if I remove the (QPushButton*) from connection and the functions it works but...if I press one button it thinks I pressed all the buttons because I'll get a cout of
but if I pressed button 0 it should only of couted "button: 0 has been pressed!" and not all the others.button: 0 has been pressed!
button: 1 has been pressed!
button: 2 has been pressed!
button: 3 has been pressed!
button: 4 has been pressed!
button: 5 has been pressed!
button: 6 has been pressed!
button: 7 has been pressed!
button: 8 has been pressed!
button: 9 has been pressed!
button: 10 has been pressed!
button: 11 has been pressed!
button: 12 has been pressed!
button: 13 has been pressed!
button: 14 has been pressed!
button: 15 has been pressed!
button: 16 has been pressed!
button: 17 has been pressed!
button: 18 has been pressed!
button: 19 has been pressed!
button: 20 has been pressed!
button: 21 has been pressed!
button: 22 has been pressed!
button: 23 has been pressed!
I can think of one way to fix this...but I would rather not do it because of time.
one fix would be to just connect each signal to a different slot and then make 24 slots and each slot do something different.
can anyone think of a way for me to have them all on one slot but do different things based on the button being pressed?
Thanks for any suggestions!
Added after 8 minutes:
sorry guys, was missing one tiny line in the slot =/
if anyone else has this problem add in this line
then just do an if statementQt Code:
To copy to clipboard, switch view to plain text mode
Qt Code:
if(button == buttonname){ //blah }To copy to clipboard, switch view to plain text mode
Bookmarks