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:
http://qt-project.org/doc/qt-4.8/qsignalmapper.html http://doc.qt.digia.com/qq/qq10-signalmapper.html#thesignalmapperapproachTo 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:
http://stackoverflow.com/questions/14151443/how-to-pass-a-qstring-to-a-qt-slot-from-a-qmenu-via-qsignalmapper-or-otherwise/14157471#14157471To 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:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDebug> #include <QSignalMapper> namespace Ui { class MainWindow; } { Q_OBJECT public: ~MainWindow(); private: Ui::MainWindow *ui; void createActions(); private slots: void interval(); void help(); int setAreaThreshold(); }; #endif // MAINWINDOW_HTo copy to clipboard, switch view to plain text mode
mainwindow.cpp
Qt Code:
#include "mainwindow.h" #include "ui_mainwindow.h" //#include "intervaldialog.h" //#include "help.h" int i =25; ui(new Ui::MainWindow) { ui->setupUi(this); createActions(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::createActions() { ui->actionInterval->setStatusTip(tr("Set the interval for capturing delta & reference images")); connect(ui->actionInterval, SIGNAL(triggered()), this, SLOT(interval())); ui->menuHelp->setStatusTip(tr("help ")); } void MainWindow::interval() { qDebug()<<"inside interval qdialog"; } int MainWindow::setAreaThreshold() { qDebug()<<"setting area threshold"; // qDebug()<<str; // int i = str.toInt(); // qDebug()<<i; // QString areaThresholdString; // areaThresholdString = ui->action25_sec->text(); // switch (areaThresholdString) { // case 25: // qDebug()<<"25"; // break; // default: // qDebug()<<"default"; // break; // } return 0; } void MainWindow::help() { Help help; help.exec(); }To copy to clipboard, switch view to plain text mode
main.cpp
Qt Code:
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { MainWindow w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Bookmarks