Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED]assign three slot to one signal.

    General and Desktop
    2
    12
    2105
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mehdi.nine last edited by

      Hi, i want assign three button's slot to a signal.
      @
      class MainWindow;
      }

      class MainWindow : public QMainWindow
      {
      Q_OBJECT

      public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      QSignalMapper *signalmapper;
      Ui::MainWindow *ui;
      void test(int);

      signals:
      void clickmee(int);
      public slots:
      void setclick1(int);
      void setclick2(int);
      void setclick3(int);

      private:

      };
      @
      i do this in constructor:
      @
      signalmapper = new QSignalMapper(this);
      signalmapper->setMapping(ui->pushButton, 10);
      signalmapper->setMapping(ui->pushButton1, 10);
      signalmapper->setMapping(ui->pushButton1, 10);
      connect(signalmapper, SIGNAL(mapped(int)),this,SIGNAL(clickmee(int)));
      @

      but when i run program in wrote:
      @
      QObject::connect: No such slot MainWindow::clickmee(int) in ..\Qsignal2\mainwindow.cpp:11
      QObject::connect: (receiver name: 'MainWindow')
      @
      how can i assign slots to signal?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        clickmee(int) is a signal not a slot

        You can't assign slot to signals, only signals to slots and signals to signals.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • M
          mehdi.nine last edited by

          how can i do that? i want to send parameter(line int) to button click event how can i do that? when i use setclick(int) the slot not working but when i using setclick() it worked. i want to pass a parameter.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            You're not really clear...

            What parameter line ?

            Also:
            @signalmapper = new QSignalMapper(this);
            signalmapper->setMapping(ui->pushButton, 10);
            signalmapper->setMapping(ui->pushButton1, 10);<-- why also 10 ?
            signalmapper->setMapping(ui->pushButton1, 10);<-- twice ?
            connect(signalmapper, SIGNAL(mapped(int)),this,SIGNAL(clickmee(int))); <-- Now a signal connected to a signal but is it really what you want ?
            @

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • M
              mehdi.nine last edited by

              oh sorry your right. i edit that. but now how can i assign all button's click to this signal i.e when i click on every buttons clickmee(int) is called? clickmee(int) is implement in .moc file so i can't use from that.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                It's done through the QSignalMapper.

                But are you sure you want clickmee to be a signal ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • M
                  mehdi.nine last edited by

                  i want to do this
                  @void setclick1(int x)
                  {
                  if(x== 10)
                  {
                  ....
                  }
                  else
                  {
                  ...
                  }

                  }
                  @
                  but this function not firing.

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    Because this slot is not connected.

                    Change your mapper connection to

                    @connect(signalmapper, SIGNAL(mapped(int)),this,SLOT(setclick1(int)));@

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply Reply Quote 0
                    • M
                      mehdi.nine last edited by

                      i do that but that's not working this is my new code:

                      @
                      class MainWindow;
                      }

                      class MainWindow : public QMainWindow
                      {
                      Q_OBJECT

                      public:
                      explicit MainWindow(QWidget *parent = 0);
                      ~MainWindow();
                      public slots:
                      void click(QString);

                      private:
                      Ui::MainWindow *ui;
                      QSignalMapper *signalmaper;

                      };@

                      .cpp
                      @
                      MainWindow::MainWindow(QWidget *parent) :
                      QMainWindow(parent),
                      ui(new Ui::MainWindow)
                      {
                      ui->setupUi(this);
                      signalmaper = new QSignalMapper(this);
                      signalmaper->setMapping(ui->pushButton, QString("dfdf"));
                      connect(signalmaper, SIGNAL(mapped(QString)),this, SLOT(click(QString)));
                      }

                      void MainWindow::click(QString x)
                      {
                      ui->pushButton->setText(x);
                      }
                      @

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        You forgot to connect the button clicked signal.

                        @connect(ui->pushButton, SIGNAL(clicked()), signalMapper, SLOT(map()));@

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply Reply Quote 0
                        • M
                          mehdi.nine last edited by

                          id didn't know that. special thanks to you .

                          1 Reply Last reply Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            Nothing special here, look at the "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details documentation

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post