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. SIGNAL / SLOT problem between 2 classes
Forum Updated to NodeBB v4.3 + New Features

SIGNAL / SLOT problem between 2 classes

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 300 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.
  • G Offline
    G Offline
    Groot
    wrote on last edited by
    #1

    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;
    
    };
    
    KroMignonK 1 Reply Last reply
    0
    • G Groot

      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;
      
      };
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @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.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      3
      • G Offline
        G Offline
        Groot
        wrote on last edited by
        #3

        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()));
        
        
        JonBJ 1 Reply Last reply
        0
        • G Groot

          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()));
          
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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);
          

          :)

          1 Reply Last reply
          1
          • G Offline
            G Offline
            Groot
            wrote on last edited by
            #5

            Ok! thanks for you help guys :)

            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