I am developing a code snippet to perform similar, not identical actions when I click on the sub menu item list. Please check the attached snapshot. QSignalMapper is the best solution to connect multiple signals to the same slot.
snap1.jpg

But I am not able to exactly place, which signal is to be called for which slot. I have read a lot of theory about QSignalMapper,
Qt Code:
  1. http://qt-project.org/doc/qt-4.8/qsignalmapper.html
  2. http://doc.qt.digia.com/qq/qq10-signalmapper.html#thesignalmapperapproach
To copy to clipboard, switch view to plain text mode 

even implemented their codes. Unlike the mentioned sample programs, my QAction objects apparently cannot be defined like we define elements inside an array, coz their names were auto-generated by the design window.
snap2.jpg

I am not able to understand, what should I place as SIGNAL here, and when should I use the setMapping function? If I use setMapping function, which parameters should I implement? I am simply not getting the concept thorough, not knowing what to do, whom to ask and making the mistake in my code here. Can you please advise me what I am doing wrong? I checked this for reference coz he had similar issue:
Qt Code:
  1. http://stackoverflow.com/questions/14151443/how-to-pass-a-qstring-to-a-qt-slot-from-a-qmenu-via-qsignalmapper-or-otherwise/14157471#14157471
To copy to clipboard, switch view to plain text mode 

Here's the code which requires 4-5 steps, which I am not getting, to be added for making it work:

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QDebug>
  6. #include <QSignalMapper>
  7.  
  8. namespace Ui {
  9. class MainWindow;
  10. }
  11.  
  12. class MainWindow : public QMainWindow
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit MainWindow(QWidget *parent = 0);
  18. ~MainWindow();
  19.  
  20.  
  21. private:
  22. Ui::MainWindow *ui;
  23. void createActions();
  24.  
  25. private slots:
  26. void interval();
  27. void help();
  28. int setAreaThreshold();
  29.  
  30. };
  31.  
  32. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. //#include "intervaldialog.h"
  4. //#include "help.h"
  5.  
  6. int i =25;
  7. MainWindow::MainWindow(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::MainWindow)
  10. {
  11. ui->setupUi(this);
  12. createActions();
  13. }
  14.  
  15. MainWindow::~MainWindow()
  16. {
  17. delete ui;
  18. }
  19.  
  20. void MainWindow::createActions()
  21. {
  22. ui->actionInterval->setStatusTip(tr("Set the interval for capturing delta & reference images"));
  23. connect(ui->actionInterval, SIGNAL(triggered()), this, SLOT(interval()));
  24.  
  25. QSignalMapper *pSignalMapper = new QSignalMapper(this);
  26. connect(ui->menuArea_Threshold, SIGNAL(triggered(QAction*)), this, SLOT(setAreaThreshold()));
  27.  
  28.  
  29. ui->menuHelp->setStatusTip(tr("help "));
  30. }
  31.  
  32. void MainWindow::interval()
  33. {
  34. qDebug()<<"inside interval qdialog";
  35. }
  36.  
  37. int MainWindow::setAreaThreshold()
  38. {
  39. qDebug()<<"setting area threshold";
  40.  
  41. // qDebug()<<str;
  42. // int i = str.toInt();
  43. // qDebug()<<i;
  44. // QString areaThresholdString;
  45. // areaThresholdString = ui->action25_sec->text();
  46. // switch (areaThresholdString) {
  47. // case 25:
  48. // qDebug()<<"25";
  49. // break;
  50. // default:
  51. // qDebug()<<"default";
  52. // break;
  53. // }
  54.  
  55. return 0;
  56. }
  57.  
  58. void MainWindow::help()
  59. {
  60. Help help;
  61. help.exec();
  62. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. w.show();
  9.  
  10. return a.exec();
  11. }
To copy to clipboard, switch view to plain text mode