Hello!
I use a QSignalMapper to map the clicked() events of a QPushButton matrix:

buttonmatrix.h:
Qt Code:
  1. #ifndef BUTTONMATRIX_H
  2. #define BUTTONMATRIX_H
  3.  
  4. #include <QPushButton>
  5. #include <QObject>
  6. #include <QSignalMapper>
  7.  
  8. class ButtonMatrix : QObject
  9. {
  10. Q_OBJECT
  11. private:
  12. int nrow;
  13. int ncol;
  14. QSignalMapper *signalMapper;
  15. public:
  16. ButtonMatrix(int nrow, int ncol);
  17. ~ButtonMatrix();
  18. void Show(QWidget*);
  19. public slots:
  20. void SetItem(const QString &ID); // this slot is called by the signal clicked() of the button identified by ID
  21. };
  22.  
  23. #endif // BUTTONMATRIX_H
To copy to clipboard, switch view to plain text mode 


buttonmatrix.cpp:
Qt Code:
  1. #include "buttonmatrix.h"
  2. #include <QPushButton>
  3. #include "mainwindow.h"
  4. #include <QSignalMapper>
  5. #include <QString>
  6. #include <QChar>
  7. #include "stdio.h"
  8. #include "mymacros.h"
  9. #include "string.h"
  10.  
  11. ButtonMatrix::ButtonMatrix(int nr, int nc)
  12. {
  13. ncol=nc;
  14. nrow = nr;
  15. p = new QPushButton*[nrow];
  16. for (int i=0; i<nrow; i++)
  17. p[i] = new QPushButton[ncol];
  18. }
  19.  
  20. void ButtonMatrix::Show(QWidget *obj)
  21. {
  22. int alt = (obj->height()-100)/nrow;
  23.  
  24. signalMapper= new QSignalMapper(this);
  25.  
  26. QString ID; // the format of the ID string will be "iijj" where i = index of rows, j = index of columns
  27. char aux1[3], aux2[3], aux3[5]; //used to convert into strings and then append the i&j indexes
  28. for (int i=0; i<nrow; i++)
  29. {
  30. if (i>=10)
  31. sprintf(aux1,"%d", i);
  32. else
  33. sprintf(aux1,"0%d", i); // this ensures that the format of the first part of ID will be "ii"
  34.  
  35. for (int j=0; j<ncol; j++)
  36. {
  37. if (j>=10)
  38. sprintf(aux2,"%d", j);
  39. else
  40. sprintf(aux2,"0%d", j); // this ensures that the format of the second part of ID will be "jj"
  41.  
  42. p[i][j].setParent(obj);
  43. p[i][j].setGeometry(50+(j*alt), 70 +(i*alt),alt, alt);
  44. connect(&p[i][j], SIGNAL(clicked()), signalMapper, SLOT(map())); //connect the clicked() slot of the ij-th button with the map() slot of the signal mapper...
  45. sprintf(aux3, "%s%s", aux1, aux2);
  46. ID = tr(aux3); // (creating the ID string in "iijj" format)
  47. signalMapper->setMapping(&p[i][j], ID); //...and then associate ID to the ij-th button of the matrix
  48. p[i][j].show();
  49. }
  50. }
  51.  
  52. connect(signalMapper, SIGNAL(mapped(const QString &)),
  53. this, SLOT(SetItem(const QString &))); // when a button of the matrix gets clicked the SetItem slot of the ButtonMatrix will be called
  54. }
  55.  
  56. void ButtonMatrix::SetItem(const QString & ID) // HERE I'd like a few more arguments for SetItem to work properly.
  57. {
  58. int i, j;
  59. const QChar *aux = ID.data();
  60. i = aux[0].digitValue()*10 + aux[1].digitValue();
  61. j = aux[2].digitValue()*10 + aux[3].digitValue();
  62.  
  63.  
  64. // here I need an integer and a custom object coming from the main
  65. //but the SLOT cannot gain more parameters than one
  66. }
  67.  
  68. ButtonMatrix::~ButtonMatrix()
  69. {
  70. for (int i=0; i<nrow; i++)
  71. delete [] p[i];
  72. delete p;
  73. }
To copy to clipboard, switch view to plain text mode 

in the code I highlited the problem. Simply I need at least two more parameters for the SLOT function that responses the clicked() SIGNALs of the button matrix, but the QSignalMapper doesn't allow me to gain more parameters than one...
is there another way to connect a button matrix without being obliged to use only one parameter in the SLOT function?

thanks