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. No matching signal AND no matching member function for call to connect
Forum Updated to NodeBB v4.3 + New Features

No matching signal AND no matching member function for call to connect

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 1.7k Views
  • 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.
  • KuvarsK Offline
    KuvarsK Offline
    Kuvars
    wrote on last edited by Kuvars
    #1

    *** Edit: This topic includes two problems. Both solved. For no matching member function for call to connect issue, see the bottom of the page. ***
    In the header file, I have defined a checkbox like following:

    public:
        QCheckBox *c1;
    

    In .cpp file, I am dynamically creating the checkbox:

    ui->setupUi(this);
    c1 = new QCheckBox(this);
    

    Since this checkbox is not visible at .ui file, I cannot right click and choose "go to slot". Instead, I have defined a similar function manually.
    Now, my header file includes:

    public:
        QCheckBox *c1;
    private slots:
        void on_c1_stateChanged(int arg1); // manually written.
    

    And I added the following fuction to my .cpp file:

    void settingsDialog::on_c1_stateChanged(int arg1)
    {
        if(arg1 == 0)
            qDebug() << "now unchecked"; 
        else if (arg1 == 2)
            qDebug() << "now checked";
    }
    

    So I am basicly trying to debug "checked" when checked, and vice versa. To do this, I have added the following code manually:

    QObject::connect( c1 , SIGNAL(stateChanged(int)) , this ,  SLOT(on_c1_stateChanged(int)));
    

    And, it works! However, everytime when I run the program, I get a warning in the application output tab:

    " QMetaObject::connectSlotsByName: No matching signal for on_c1_stateChanged(int). "

    Although it works, I just wanted to be sure that it will not cause any errors in the future. Do I have any mistake in my QObject::connect(...) function?

    Thank you in advance!

    Christian EhrlicherC 1 Reply Last reply
    0
    • KuvarsK Kuvars

      *** Edit: This topic includes two problems. Both solved. For no matching member function for call to connect issue, see the bottom of the page. ***
      In the header file, I have defined a checkbox like following:

      public:
          QCheckBox *c1;
      

      In .cpp file, I am dynamically creating the checkbox:

      ui->setupUi(this);
      c1 = new QCheckBox(this);
      

      Since this checkbox is not visible at .ui file, I cannot right click and choose "go to slot". Instead, I have defined a similar function manually.
      Now, my header file includes:

      public:
          QCheckBox *c1;
      private slots:
          void on_c1_stateChanged(int arg1); // manually written.
      

      And I added the following fuction to my .cpp file:

      void settingsDialog::on_c1_stateChanged(int arg1)
      {
          if(arg1 == 0)
              qDebug() << "now unchecked"; 
          else if (arg1 == 2)
              qDebug() << "now checked";
      }
      

      So I am basicly trying to debug "checked" when checked, and vice versa. To do this, I have added the following code manually:

      QObject::connect( c1 , SIGNAL(stateChanged(int)) , this ,  SLOT(on_c1_stateChanged(int)));
      

      And, it works! However, everytime when I run the program, I get a warning in the application output tab:

      " QMetaObject::connectSlotsByName: No matching signal for on_c1_stateChanged(int). "

      Although it works, I just wanted to be sure that it will not cause any errors in the future. Do I have any mistake in my QObject::connect(...) function?

      Thank you in advance!

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kuvars said in No matching signal:

      " QMetaObject::connectSlotsByName: No matching signal for on_c1_stateChanged(int). "
      Although it works, I just wanted to be sure that it will not cause any errors in the future. Do I have any mistake in my QObject::connect(...) function?

      1. Use the 'new' signal and slot syntax to catch connection errors on compile time rather than runtime
      2. Due to your naming of your slot you trigger the auto-connect feature of Qt which then complains that it can't find the approriate stuff - rename your slot (do not start with on_ or ignore the message)

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      KuvarsK 2 Replies Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @Kuvars said in No matching signal:

        " QMetaObject::connectSlotsByName: No matching signal for on_c1_stateChanged(int). "
        Although it works, I just wanted to be sure that it will not cause any errors in the future. Do I have any mistake in my QObject::connect(...) function?

        1. Use the 'new' signal and slot syntax to catch connection errors on compile time rather than runtime
        2. Due to your naming of your slot you trigger the auto-connect feature of Qt which then complains that it can't find the approriate stuff - rename your slot (do not start with on_ or ignore the message)
        KuvarsK Offline
        KuvarsK Offline
        Kuvars
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Thank you, sir!
        For other people who might wonder the solution:

        I have changed the name of my fuction from "on_c1_stateChanged(int arg1)" to "on_c1StateChanged(int arg1)".
        In brief, changing the name indeed solves the issue.

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @Kuvars said in No matching signal:

          " QMetaObject::connectSlotsByName: No matching signal for on_c1_stateChanged(int). "
          Although it works, I just wanted to be sure that it will not cause any errors in the future. Do I have any mistake in my QObject::connect(...) function?

          1. Use the 'new' signal and slot syntax to catch connection errors on compile time rather than runtime
          2. Due to your naming of your slot you trigger the auto-connect feature of Qt which then complains that it can't find the approriate stuff - rename your slot (do not start with on_ or ignore the message)
          KuvarsK Offline
          KuvarsK Offline
          Kuvars
          wrote on last edited by Kuvars
          #4

          @Christian-Ehrlicher
          Hello again, now I have another question related to it. I can successfully connect in two ways:

          QObject::connect( c1, SIGNAL(stateChanged(int)) , this , SLOT( function1() ));  // old syntax
          QObject::connect( c1, &QCheckBox::stateChanged, this, &settingsDialog::fuction1); // new syntax
          

          Now, instead of connecting it to function1 in my settingsDialog class, I want to connect it to function2 in another class, called MainWindow. I try to do this as:

          QObject::connect( c1,  &QCheckBox::stateChanged , this , &MainWindow::function2);
          

          However, it gives the following error: No matching member function for call to 'connect'.

          Both function1() and function2() are defined as public slots. Also, in the header files of both classes, there is Q_OBJECT Macro:

          class settingsDialog : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit settingsDialog(QWidget *parent = nullptr);
              ~settingsDialog();
          
          public slots:
             void function1();
          
          // other fuctions and data members
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              MainWindow(QWidget *parent = nullptr);
              ~MainWindow();
          
          public slots:
              void function2();
          
          // other functions and data members
          };
          
          

          Couldn't solve it. I hope you guys help, thank you in advance.

          JonBJ 1 Reply Last reply
          0
          • KuvarsK Kuvars

            @Christian-Ehrlicher
            Hello again, now I have another question related to it. I can successfully connect in two ways:

            QObject::connect( c1, SIGNAL(stateChanged(int)) , this , SLOT( function1() ));  // old syntax
            QObject::connect( c1, &QCheckBox::stateChanged, this, &settingsDialog::fuction1); // new syntax
            

            Now, instead of connecting it to function1 in my settingsDialog class, I want to connect it to function2 in another class, called MainWindow. I try to do this as:

            QObject::connect( c1,  &QCheckBox::stateChanged , this , &MainWindow::function2);
            

            However, it gives the following error: No matching member function for call to 'connect'.

            Both function1() and function2() are defined as public slots. Also, in the header files of both classes, there is Q_OBJECT Macro:

            class settingsDialog : public QDialog
            {
                Q_OBJECT
            
            public:
                explicit settingsDialog(QWidget *parent = nullptr);
                ~settingsDialog();
            
            public slots:
               void function1();
            
            // other fuctions and data members
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                MainWindow(QWidget *parent = nullptr);
                ~MainWindow();
            
            public slots:
                void function2();
            
            // other functions and data members
            };
            
            

            Couldn't solve it. I hope you guys help, thank you in advance.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Kuvars said in No matching signal:

            QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);

            What is this? Is it still settingsDialog and not MainWindow? And anyway you should never connect to MainWindow-anything other than from inside MainWindow (nor include mainwindow.h anywhere other than in mainwindow.cpp).

            KuvarsK 1 Reply Last reply
            1
            • JonBJ JonB

              @Kuvars said in No matching signal:

              QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);

              What is this? Is it still settingsDialog and not MainWindow? And anyway you should never connect to MainWindow-anything other than from inside MainWindow (nor include mainwindow.h anywhere other than in mainwindow.cpp).

              KuvarsK Offline
              KuvarsK Offline
              Kuvars
              wrote on last edited by
              #6

              @JonB
              Let me summarize what I am trying to do. I have a mainwindow class that I perform most operations. In its header file, I have defined:

              SettingsDialog *settingsPage;
              

              In the constructor in .cpp file of maindwindow, I am creating it dynamically:

              settingsPage = new SettingsDialog(this);
              

              The reason what I am doing is that, I will add checkboxes to this dialog, and if I check those checkboxes and close the dialog, I want them to remain their state. For instance, when I open the dialog again by clicking a button on mainwindow, I will see that they are still checked on settingsdialog.

              In a button on mainwindow, I am opening setttings dialog by:

              settingsPage->show();
              

              Now, here is the problematic part:
              My aim is, when I changed the state of a checbox on settingsdialog, I want to change the value of a variable in mainwindow. For instance, in mainwindow, now there is an integer: int var = 0; Everytime when I check the checkbox on settingsdialog, I want the "var"in mainwindow to become 1, and everytime when I uncheck it, I want it to become 2, lets say.

              To do this, I need to add signal and slot to checkbox. If I choose a slot function in settingsdialog, I cannot access mainwindows's "var" from settingsdialog class, because I don't have an object of mainwindow class to access its data member or functions. Instead, I am trying to connect the checkbox in settingsdialog to a function in mainwindow, so that evertime the state of the checkbox in settingdialog changes, it will call a fuction in mainwindow, and so that I can access "var" within this function.

              Thats why I am trying to connect like:

              QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);
              

              where function2 is the function in mainwindow.

              I hope I could explain my purpose. Thank you in advance for your help.

              JonBJ 1 Reply Last reply
              0
              • KuvarsK Kuvars

                @JonB
                Let me summarize what I am trying to do. I have a mainwindow class that I perform most operations. In its header file, I have defined:

                SettingsDialog *settingsPage;
                

                In the constructor in .cpp file of maindwindow, I am creating it dynamically:

                settingsPage = new SettingsDialog(this);
                

                The reason what I am doing is that, I will add checkboxes to this dialog, and if I check those checkboxes and close the dialog, I want them to remain their state. For instance, when I open the dialog again by clicking a button on mainwindow, I will see that they are still checked on settingsdialog.

                In a button on mainwindow, I am opening setttings dialog by:

                settingsPage->show();
                

                Now, here is the problematic part:
                My aim is, when I changed the state of a checbox on settingsdialog, I want to change the value of a variable in mainwindow. For instance, in mainwindow, now there is an integer: int var = 0; Everytime when I check the checkbox on settingsdialog, I want the "var"in mainwindow to become 1, and everytime when I uncheck it, I want it to become 2, lets say.

                To do this, I need to add signal and slot to checkbox. If I choose a slot function in settingsdialog, I cannot access mainwindows's "var" from settingsdialog class, because I don't have an object of mainwindow class to access its data member or functions. Instead, I am trying to connect the checkbox in settingsdialog to a function in mainwindow, so that evertime the state of the checkbox in settingdialog changes, it will call a fuction in mainwindow, and so that I can access "var" within this function.

                Thats why I am trying to connect like:

                QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);
                

                where function2 is the function in mainwindow.

                I hope I could explain my purpose. Thank you in advance for your help.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Kuvars said in No matching signal:

                Instead, I am trying to connect the checkbox in settingsdialog to a function in mainwindow

                QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);

                So just as i asked, what is this? This is in settingsdialog, right? So this is not MainWindow, so your slot connection cannot be made.

                As stated earlier, you never should connect to, or even access, anything in MainWindow from elsewhere. connect()s must be placed somewhere which can access the slot (as well the signal), do not connect from where the signal is to some "outside world" slot.

                You need to move the connection into MainWindow, where the slot is. You will either have to export settingsDialog.c1 so that main window can use it for the signaller, or you will need to create your own signal to emit from settingsDialog which main window can connect from and have the dialog do its own internal connection on c1 to emit that dialog signal.

                KuvarsK 1 Reply Last reply
                3
                • JonBJ JonB

                  @Kuvars said in No matching signal:

                  Instead, I am trying to connect the checkbox in settingsdialog to a function in mainwindow

                  QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);

                  So just as i asked, what is this? This is in settingsdialog, right? So this is not MainWindow, so your slot connection cannot be made.

                  As stated earlier, you never should connect to, or even access, anything in MainWindow from elsewhere. connect()s must be placed somewhere which can access the slot (as well the signal), do not connect from where the signal is to some "outside world" slot.

                  You need to move the connection into MainWindow, where the slot is. You will either have to export settingsDialog.c1 so that main window can use it for the signaller, or you will need to create your own signal to emit from settingsDialog which main window can connect from and have the dialog do its own internal connection on c1 to emit that dialog signal.

                  KuvarsK Offline
                  KuvarsK Offline
                  Kuvars
                  wrote on last edited by
                  #8

                  @JonB said in No matching signal:

                  or you will need to create your own signal to emit from settingsDialog which main window can connect from and have the dialog do its own internal connection on c1 to emit that dialog signal.

                  That is what I am trying to do sir, how can I modify :

                  QObject::connect( c1, &QCheckBox::stateChanged , this , &MainWindow::function2);
                  

                  I apologize, new in Qt. Should I also change the 3rd argument (this) to be able to do that? I appreciate if it is possible for you to illustrate it with a short code segment.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dan1973
                    wrote on last edited by
                    #9
                    ChkBox1::ChkBox1(QWidget *parent) :
                        QWidget(parent),
                        ui(new Ui::ChkBox1)
                    {
                        ui->setupUi(this);
                    
                        chbTest = new QCheckBox(tr("Hide this window"));
                        connect(chbTest, SIGNAL(clicked(bool)), SLOT(HideWindow()));
                    
                        vbxTest = new QVBoxLayout;
                        vbxTest->addWidget(chbTest);
                    
                        setLayout(vbxTest);
                        setWindowTitle(tr("Check Box demo"));
                    }
                    
                    ChkBox1::~ChkBox1()
                    {
                        delete ui;
                    }
                    
                    void ChkBox1::HideWindow() {
                        if(chbTest->isChecked()) {
                            QMessageBox msg1;
                            msg1.setText(tr("Hai"));
                            msg1.exec();
                        }
                    }
                    

                    Hope this helps

                    KuvarsK 1 Reply Last reply
                    1
                    • D dan1973
                      ChkBox1::ChkBox1(QWidget *parent) :
                          QWidget(parent),
                          ui(new Ui::ChkBox1)
                      {
                          ui->setupUi(this);
                      
                          chbTest = new QCheckBox(tr("Hide this window"));
                          connect(chbTest, SIGNAL(clicked(bool)), SLOT(HideWindow()));
                      
                          vbxTest = new QVBoxLayout;
                          vbxTest->addWidget(chbTest);
                      
                          setLayout(vbxTest);
                          setWindowTitle(tr("Check Box demo"));
                      }
                      
                      ChkBox1::~ChkBox1()
                      {
                          delete ui;
                      }
                      
                      void ChkBox1::HideWindow() {
                          if(chbTest->isChecked()) {
                              QMessageBox msg1;
                              msg1.setText(tr("Hai"));
                              msg1.exec();
                          }
                      }
                      

                      Hope this helps

                      KuvarsK Offline
                      KuvarsK Offline
                      Kuvars
                      wrote on last edited by Kuvars
                      #10

                      @dan1973
                      YESS! It helped, thank you! and also thanks to @JonB !

                      Here is how I handled the problem in mainwindow . cpp file by analyzing your code segment:

                      MainWindow::MainWindow(QWidget *parent)
                          : QMainWindow(parent)
                          , ui(new Ui::MainWindow)
                      {
                          ui->setupUi(this);
                          settingPage = new settingsDialog(this);
                          QObject::connect(settingPage->c1 ,&QCheckBox::stateChanged, this, &MainWindow::function2) 
                      }
                      

                      So that I could access the checkbox on settingsdialog by settingspage object and "->" operator. Also, the connect() fuction and the slot function2() are in the mainwindow as JohnB suggested.
                      Thank you all!

                      D 1 Reply Last reply
                      1
                      • KuvarsK Kuvars

                        @dan1973
                        YESS! It helped, thank you! and also thanks to @JonB !

                        Here is how I handled the problem in mainwindow . cpp file by analyzing your code segment:

                        MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent)
                            , ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                            settingPage = new settingsDialog(this);
                            QObject::connect(settingPage->c1 ,&QCheckBox::stateChanged, this, &MainWindow::function2) 
                        }
                        

                        So that I could access the checkbox on settingsdialog by settingspage object and "->" operator. Also, the connect() fuction and the slot function2() are in the mainwindow as JohnB suggested.
                        Thank you all!

                        D Offline
                        D Offline
                        dan1973
                        wrote on last edited by
                        #11

                        @Kuvars Please mark as solved. Thanks.

                        1 Reply Last reply
                        0

                        • Login

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