There is a button in ob_panel.ui - on_pB_Switch_clicked and an element in mainwindow.ui - MapToolKit . When I click on a button in ob_panel.ui I try to hide the element located in mainwindow.ui .

MainWindow.cpp

 connect(&Ob_Panel, &ob_panel::on_pB_Switch_clicked, this, &MainWindow::switchVideoMap); void MainWindow::switchVideoMap(){ ui->MapToolKit->hide(); } 

MainWindow.h

 #include <ob_panel.h> private slots: void switchVideoMap(); private: ob_panel *Ob_Panel 

ob_panel.cpp

 void ob_panel::on_pB_Switch_clicked(){ } 

ob_panel.h

 public: void on_pB_Switch_clicked(); 

Error compiled when compiling

 ../mainwindow.cpp:52: error: no matching function for call to 'MainWindow::connect(ob_panel**, void (ob_panel::*)(), MainWindow* const, void (MainWindow::*)())' connect(&Ob_Panel, &ob_panel::on_pB_Switch_clicked, this, &MainWindow::switchVideoMap); ^ 
  • one
    public: void on_pB_Switch_clicked (); <Is it a signal or a slot? Indicate this correctly: signals: void on_pB_Switch_clicked (); or public slots: void on_pB_Switch_clicked (); - Xplatforms

1 answer 1

Ob_Panel you and so the pointer, you do not need to take the address from the connect

 connect(Ob_Panel, &ob_panel::on_pB_Switch_clicked, this, &MainWindow::switchVideoMap); 
  • compilation of prol, but unfortunately gives an error when you click on the button QObject::connect: signal not found in ob_panel - Insider
  • @Insider, here you should already use the @Xplatforms advice and arrange the signal section as signals rather than public (in ob_panel.h). - free_ze
  • at registration in the section of the sequential void ob_panel::on_pB_Switch_clicked() { QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR); } void ob_panel::on_pB_Switch_clicked() { QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR); } I get the following error ../moc_ob_panel.cpp:133: error: multiple definition of ``ob_panel::on_pB_Switch_clicked()' - Insider
  • @Insider oh) It is necessary to remove (in general!) The implementation of the signal from cpp. Qt MOC tries to generate it and bumps into yours. - free_ze
  • I realized) my almost the very first experiences with this). And if I add some events to the button additionally, what should I do? - Insider