I made a custom slot for when one of my buttons get clicked on. When this button is clicked, it is to access some other buttons and change some of their properties like setText etc.

I finally managed to get my button connected with the slot, but I can't figure out how to access the button from the slot. I tried passing the button, passing it by reference, and passing a pointer, but anytime I try to pass something it fails to connect the slot. Here is my current code without passing anything. This is just a test that I've been playing around with.

I might add that I am a complete newbie at this. I have a programming assignment due Friday that is to make a minesweeper game, so I have a week to learn enough Qt to make it work. I had never even heard of Qt until 2 days ago. What I really need to do is add a unique id to each button so I can access them like that, but I figured I needed to know how to get the slot working first.

Any help or tips would be much appreciated, Thanks!

Qt Code:
  1. #ifndef MYWIDGET_H
  2. #define MYWIDGET_H
  3.  
  4. #include <QApplication>
  5. #include <QFont>
  6. #include <QGridLayout>
  7. #include <QPushButton>
  8. #include <QWidget>
  9. #include <QDebug>
  10.  
  11. class MyWidget : public QWidget
  12. {
  13. Q_OBJECT
  14.  
  15. public slots:
  16. void buttonClicked();
  17.  
  18. public:
  19. MyWidget(QWidget *parent = 0);
  20.  
  21. };
  22.  
  23. #endif // MYWIDGET_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "MyWidget.h"
  2.  
  3. void MyWidget::buttonClicked()
  4. {
  5. //Here is where I need to access the button properties. I never could figure out how to reach the button.
  6.  
  7.  
  8. }
  9.  
  10. MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
  11. {
  12.  
  13. //This just makes a grid of a few buttons, and plays with some of the options like setting the text etc for testing purposes.
  14.  
  15. QGridLayout *grid = new QGridLayout;
  16. grid->setSpacing(2);
  17. for (int row = 0; row < 10; ++row) {
  18. for (int column = 0; column < 10; ++column) {
  19. QPushButton *button = new QPushButton;
  20. button->setMinimumSize(5,5);
  21. button->resize(300/20,300/20);
  22. if ( row == 2 ) button->setText("A");
  23. if ( column == 2 ) button->setFlat(true);
  24. button->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,
  25. QSizePolicy::Expanding));
  26.  
  27. connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
  28.  
  29. grid->addWidget(button, row, column);
  30. }
  31. }
  32.  
  33. setLayout(grid);
  34. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include <QApplication>
  2. #include <QFont>
  3. #include <QGridLayout>
  4. #include <QPushButton>
  5. #include <QWidget>
  6. #include <QDebug>
  7. #include "MyWidget.h"
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11. QApplication app(argc, argv);
  12. MyWidget widget;
  13. widget.show();
  14. widget.resize(300,300);
  15. return app.exec();
  16. }
To copy to clipboard, switch view to plain text mode