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. Slot and Signal problem custom class
Qt 6.11 is out! See what's new in the release blog

Slot and Signal problem custom class

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.3k 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.
  • V Offline
    V Offline
    vin212
    wrote on last edited by vin212
    #1

    Hello,

    I have a problem, i create one class for the differente action and i would like put the different slot on this class. But, when i create the connexion, it use the slot on the class for my ui and not in my class.

    I explaine : My ui is in the class "MainWindowTracage." and the slot, i put on the class "MainWindowsAction." but, if i create the signal with this line : connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(test()) ); on the class MainWindows Action it don't work.
    I have this error message :

    QObject::connect: No such slot QMainWindow::test() in ..\ihm_tracage\src\mainwindowsaction.cpp:8
    QObject::connect:  (sender name:   'pushButton')
    
    

    Do you have any solution for fixe my problem ?

    the code :
    mainwindowsaction.cpp :

    #include "header\mainwindowsaction.h"
    
    MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action)
    {
        this->window = window;
        this->affichage = affichage;
    
        connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );
    
    }
    
    void MainWindowsAction::test()
    {
        printf("ok");
    }
    
    

    mainwindowsaction.h :

    #ifndef MAINWINDOWSACTION_H
    #define MAINWINDOWSACTION_H
    
    #include "mainwindowsaffichageMe.h"
    #include "mainwindowtracage.h"
    
    #include "ui_mainwindowtracage.h"
    
    class MainWindowsAction : public QMainWindow
    {
        public:
            MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);
        public slots:
            void test();
        private:
            MainWindowTracage *window;
            MainWindowsAffichageMe *affichage;
    ;
    };
    
    
    

    thank's for your answer !

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • V vin212

      Hello,

      I have a problem, i create one class for the differente action and i would like put the different slot on this class. But, when i create the connexion, it use the slot on the class for my ui and not in my class.

      I explaine : My ui is in the class "MainWindowTracage." and the slot, i put on the class "MainWindowsAction." but, if i create the signal with this line : connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(test()) ); on the class MainWindows Action it don't work.
      I have this error message :

      QObject::connect: No such slot QMainWindow::test() in ..\ihm_tracage\src\mainwindowsaction.cpp:8
      QObject::connect:  (sender name:   'pushButton')
      
      

      Do you have any solution for fixe my problem ?

      the code :
      mainwindowsaction.cpp :

      #include "header\mainwindowsaction.h"
      
      MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action)
      {
          this->window = window;
          this->affichage = affichage;
      
          connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );
      
      }
      
      void MainWindowsAction::test()
      {
          printf("ok");
      }
      
      

      mainwindowsaction.h :

      #ifndef MAINWINDOWSACTION_H
      #define MAINWINDOWSACTION_H
      
      #include "mainwindowsaffichageMe.h"
      #include "mainwindowtracage.h"
      
      #include "ui_mainwindowtracage.h"
      
      class MainWindowsAction : public QMainWindow
      {
          public:
              MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);
          public slots:
              void test();
          private:
              MainWindowTracage *window;
              MainWindowsAffichageMe *affichage;
      ;
      };
      
      
      

      thank's for your answer !

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

      @vin212
      Start by changing over to New Signal Slot Syntax instead of using your SIGNAL/SLOT() macros, the compile-time errors you will receive while you get your code right will be much more helpful.

      From the error message you show you cannot have action, SLOT(MainWindowsAction::test()) in your connect(). And/or you reference a QMainWindow::test() on the line it tells you, and there is no such slot.

      1 Reply Last reply
      1
      • V vin212

        Hello,

        I have a problem, i create one class for the differente action and i would like put the different slot on this class. But, when i create the connexion, it use the slot on the class for my ui and not in my class.

        I explaine : My ui is in the class "MainWindowTracage." and the slot, i put on the class "MainWindowsAction." but, if i create the signal with this line : connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(test()) ); on the class MainWindows Action it don't work.
        I have this error message :

        QObject::connect: No such slot QMainWindow::test() in ..\ihm_tracage\src\mainwindowsaction.cpp:8
        QObject::connect:  (sender name:   'pushButton')
        
        

        Do you have any solution for fixe my problem ?

        the code :
        mainwindowsaction.cpp :

        #include "header\mainwindowsaction.h"
        
        MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action)
        {
            this->window = window;
            this->affichage = affichage;
        
            connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );
        
        }
        
        void MainWindowsAction::test()
        {
            printf("ok");
        }
        
        

        mainwindowsaction.h :

        #ifndef MAINWINDOWSACTION_H
        #define MAINWINDOWSACTION_H
        
        #include "mainwindowsaffichageMe.h"
        #include "mainwindowtracage.h"
        
        #include "ui_mainwindowtracage.h"
        
        class MainWindowsAction : public QMainWindow
        {
            public:
                MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);
            public slots:
                void test();
            private:
                MainWindowTracage *window;
                MainWindowsAffichageMe *affichage;
        ;
        };
        
        
        

        thank's for your answer !

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @vin212 you're missing Q_OBJECTmacro in your header, old qt4 connect syntax does not work without it.
        also action is wrong here as receiver object, it ought to be this

        all in all its this quite wrong:

        connect(window->ui->pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );
        

        thats mixing syntaxes

        connect(window->ui->pushButton, SIGNAL(clicked()),this, SLOT(test()) );
        

        or preferably

        connect(window->ui->pushButton, &QPushButton::clicked, this ,&MainWindowsAction::test );
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • V Offline
          V Offline
          vin212
          wrote on last edited by vin212
          #4

          Ok !

          I change for :

          connect(window->ui->pushButton, &QPushButton::clicked,this, &MainWindowsAction::test );
          
          
          

          and i add Q_OBJECT
          but i have an other error message :

          mainwindowsaction.cpp:3: erreur : undefined reference to `vtable for MainWindowsAction'
          debug/mainwindowsaction.o: In function `ZN17MainWindowsActionC2EP17MainWindowTracageP22MainWindowsAffichageMePS_':
          mainwindowsaction.cpp:3: undefined reference to `vtable for MainWindowsAction'
          

          I add the destructor and is the same.

          J.HilkJ JonBJ 2 Replies Last reply
          0
          • V vin212

            Ok !

            I change for :

            connect(window->ui->pushButton, &QPushButton::clicked,this, &MainWindowsAction::test );
            
            
            

            and i add Q_OBJECT
            but i have an other error message :

            mainwindowsaction.cpp:3: erreur : undefined reference to `vtable for MainWindowsAction'
            debug/mainwindowsaction.o: In function `ZN17MainWindowsActionC2EP17MainWindowTracageP22MainWindowsAffichageMePS_':
            mainwindowsaction.cpp:3: undefined reference to `vtable for MainWindowsAction'
            

            I add the destructor and is the same.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @vin212
            seems like the compiler was unable to properly construct the polymorphism relations

            My bet would be because your only constructor
            MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);

            requieres a pointer to an other instance of your class.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            V 2 Replies Last reply
            0
            • J.HilkJ J.Hilk

              @vin212
              seems like the compiler was unable to properly construct the polymorphism relations

              My bet would be because your only constructor
              MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);

              requieres a pointer to an other instance of your class.

              V Offline
              V Offline
              vin212
              wrote on last edited by vin212
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @vin212
                seems like the compiler was unable to properly construct the polymorphism relations

                My bet would be because your only constructor
                MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);

                requieres a pointer to an other instance of your class.

                V Offline
                V Offline
                vin212
                wrote on last edited by
                #7

                @J-Hilk

                Yes, it's maybe this problem, i recompile and it's work

                Thank's for your answers

                KroMignonK 1 Reply Last reply
                0
                • V vin212

                  Ok !

                  I change for :

                  connect(window->ui->pushButton, &QPushButton::clicked,this, &MainWindowsAction::test );
                  
                  
                  

                  and i add Q_OBJECT
                  but i have an other error message :

                  mainwindowsaction.cpp:3: erreur : undefined reference to `vtable for MainWindowsAction'
                  debug/mainwindowsaction.o: In function `ZN17MainWindowsActionC2EP17MainWindowTracageP22MainWindowsAffichageMePS_':
                  mainwindowsaction.cpp:3: undefined reference to `vtable for MainWindowsAction'
                  

                  I add the destructor and is the same.

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

                  @vin212 said in Slot and Signal problem custom class:

                  and i add Q_OBJECT

                  Regardless of any other issues. Any time you add Q_OBJECT to an already defined and compiled class you must do a complete rebuild. This is a known practicality. If you do not, you are liable to get precisely the vtable error you got for that class.

                  1 Reply Last reply
                  0
                  • V vin212

                    @J-Hilk

                    Yes, it's maybe this problem, i recompile and it's work

                    Thank's for your answers

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #9

                    @vin212 said in Slot and Signal problem custom class:

                    I change for :

                        connect(window->ui->pushButton, &QPushButton::clicked,this, &MainWindowsAction::test );
                    

                    and i add Q_OBJECT
                    but i have an other error message :

                    Yes, it's maybe this problem, i recompile and it's work
                    Thank's for your answers

                    After adding Q_OBJECT to a class, you need rerun moc (Meta-Object Compiler).
                    Take a look at following links for more details!

                    • https://doc.qt.io/qt-5/moc.html
                    • https://doc.qt.io/qt-5/why-moc.html

                    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
                    0

                    • Login

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