Hi,
I am dynamically creating QPushButtons in ui and holding them in array. After clicking one of them I want to call function with integer parameter. It will be button index in array so I need to know which button was clicked to call this function.

I coded like this:

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent, struct ProfileParams profPar) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6. this->showMaximized();
  7. QPushButton * btn[16];
  8. QSignalMapper* sendSignalMapper = new QSignalMapper(this);//sendMessage
  9. int k = 0, l = 1, a = 0;
  10.  
  11. for(int j=1; j<=profPar.number; j++)
  12. {
  13. btn[j-1] = new QPushButton;
  14. btn[j-1]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  15. sendSignalMapper->setMapping(btn[j-1],j-1);
  16. connect(btn[j-1],SIGNAL(clicked()),sendSignalMapper,SLOT(map()));
  17. }
  18. connect(sendSignalMapper,SIGNAL(mapped(int)),this ,SLOT(send_data(int)));
  19. }
  20. else
  21. {
  22. QMessageBox::critical(this,"Error", "Cannot open!", QMessageBox::Ok);
  23. exit(0);
  24. }
  25. }
  26.  
  27. void MainWindow::send_data(int number)
  28. {
  29. sendDat("#WAIT", number);
  30. }
To copy to clipboard, switch view to plain text mode 

and it isn't working - why?

sorry for my "English"