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. signalMapper
Forum Updated to NodeBB v4.3 + New Features

signalMapper

Scheduled Pinned Locked Moved Unsolved General and Desktop
signalmapper
5 Posts 3 Posters 1.5k Views 2 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.
  • N Offline
    N Offline
    Nirvana
    wrote on 23 Jan 2016, 04:12 last edited by
    #1

    I have been looking docs and other topics about singalMappers but I still couldn't make it work properly.

    here is the function I want to call

    void theme(QString a)
    {

    qDebug()<<a;
    

    }

    here is how I connected
    for (int a=0;a<buttons.count();a++){
    QPushButton *button = new QPushButton();

        QSignalMapper *signalMapper = new QSignalMapper();
    
        connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(theme(QString)));
    
        connect(button,  SIGNAL(clicked()), signalMapper,SLOT(map()));
        signalMapper->setMapping(button,button->text());
    

    here is the header file

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    signals:
    void theme(QString a);

    private slots:
    void on_pushButton_clicked();

    void on_pushButton_10_clicked();
    
    void on_temalar_button_clicked();
    

    public:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H

    But when I click the button, I don't get any debug output. What is the thing that I'm doing wrongly?
    Thanks

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 23 Jan 2016, 10:52 last edited by
      #2

      Hi!
      I think that

      connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(theme(QString)));
      

      should be

      connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(theme(QString)));
      
      N 1 Reply Last reply 23 Jan 2016, 12:28
      0
      • ? A Former User
        23 Jan 2016, 10:52

        Hi!
        I think that

        connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(theme(QString)));
        

        should be

        connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(theme(QString)));
        
        N Offline
        N Offline
        Nirvana
        wrote on 23 Jan 2016, 12:28 last edited by
        #3

        @Wieland
        I did but it is still not working.
        I put theme from signals: to slots: in header file. And did what you said, now I'm having this:

        /home/metin/QTProjects/build-settings-Desktop_Qt_5_5_1_GCC_64bit-Debug/moc_mainwindow.cpp:82: error: undefined reference to `MainWindow::theme(QString)'

        ? 1 Reply Last reply 23 Jan 2016, 13:20
        0
        • N Nirvana
          23 Jan 2016, 12:28

          @Wieland
          I did but it is still not working.
          I put theme from signals: to slots: in header file. And did what you said, now I'm having this:

          /home/metin/QTProjects/build-settings-Desktop_Qt_5_5_1_GCC_64bit-Debug/moc_mainwindow.cpp:82: error: undefined reference to `MainWindow::theme(QString)'

          ? Offline
          ? Offline
          A Former User
          wrote on 23 Jan 2016, 13:20 last edited by
          #4

          @Nirvana You probably need to clean your project and run qmake again.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 23 Jan 2016, 21:43 last edited by
            #5

            Hi and welcome to devnet,

            MainWindow's theme is a signal so basically your initial connect line was correct from that perspective. However, your theme function is just a static function somewhere.

            If you want it to be called, you should make theme a slot, and add the missing MainWindow:: between void and theme and keep the new version of the connect statement.

            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

            1/5

            23 Jan 2016, 04:12

            • Login

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