Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]assign three slot to one signal.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]assign three slot to one signal.

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 2.5k Views 1 Watching
  • 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 Offline
    M Offline
    mehdi.nine
    wrote on 23 Apr 2013, 19:13 last edited by
    #3

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Apr 2013, 19:18 last edited by
      #4

      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
      0
      • M Offline
        M Offline
        mehdi.nine
        wrote on 23 Apr 2013, 19:23 last edited by
        #5

        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
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 23 Apr 2013, 19:37 last edited by
          #6

          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
          0
          • M Offline
            M Offline
            mehdi.nine
            wrote on 23 Apr 2013, 19:38 last edited by
            #7

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

            }
            @
            but this function not firing.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 23 Apr 2013, 20:06 last edited by
              #8

              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
              0
              • M Offline
                M Offline
                mehdi.nine
                wrote on 23 Apr 2013, 20:17 last edited by
                #9

                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
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 23 Apr 2013, 20:20 last edited by
                  #10

                  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
                  0
                  • M Offline
                    M Offline
                    mehdi.nine
                    wrote on 23 Apr 2013, 20:22 last edited by
                    #11

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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 23 Apr 2013, 20:37 last edited by
                      #12

                      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
                      0

                      12/12

                      23 Apr 2013, 20:37

                      • Login

                      • Login or register to search.
                      12 out of 12
                      • First post
                        12/12
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved