Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

SIGNAL / SLOT problem between 2 classes



  • Hello all :)

    I have 2 ui classes into an "Application" class

    class Application
    		{
    		public:
    			Application();
    			Application(QString name, QString version);
    			void run();
    
    		private:
    
    			QString name_;
    			QString version_;
    
    			/********* UI ********/
    			Menu_ui menu_;
    			Employee_sheet_ui employee_sheet_;
    
    			/**********************/
    		};
    

    I want to show "employee_sheet_ when I press a button from "menu_"
    ATM, I thought it was necessary to do like that:

    void Application::run()
    {
    	menu_.show();
    
    	QObject::connect(menu_.ui.pushButton, SIGNAL(clicked()), &employee_sheet_, SLOT(employee_sheet_.show()));
    }
    

    ...but it doesn't work

    Someone can explain me my error please?

    Thanks a lot in advance :)

    For information, my Enployee_sheet class:

    #include <QWidget>
    #include "ui_employee_sheet_ui.h"
    
    class Employee_sheet_ui : public QWidget
    {
    	Q_OBJECT
    
    public:
    	Employee_sheet_ui(QWidget *parent = Q_NULLPTR);
    	~Employee_sheet_ui();
    
    
    	Ui::Employee_sheet_ui ui;
    
    };
    


  • @Groot said in SIGNAL / SLOT problem between 2 classes:

    Someone can explain me my error please?

    Your connect() is wrong => please take time to read documentation: https://doc.qt.io/qt-5/signalsandslots.html
    And prefere using new connect syntax so you will get connection error at compilation time.



  • I have understand! i'm stupid! (thx Lelev)

    I must remplace:

    QObject::connect(menu_.ui.pushButton, SIGNAL(clicked()), &employee_sheet_, SLOT(employee_sheet_.show()));
    

    to:

    	QObject::connect(menu_.ui.pushButton, SIGNAL(clicked()), &employee_sheet_, SLOT(show()));
    
    


  • @Groot
    Yes, but as @KroMignon said it would be even better if you decided to change over to:

    QObject::connect(menu_.ui.pushButton, &QPushButton::clicked, &employee_sheet_, &EmployeeSheet::show);
    

    :)



  • Ok! thanks for you help guys :)


Log in to reply