Slot and Signal problem custom class
-
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 !
-
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 !
@vin212
Start by changing over to New Signal Slot Syntax instead of using yourSIGNAL/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 yourconnect(). And/or you reference aQMainWindow::test()on the line it tells you, and there is no such slot. -
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 !
@vin212 you're missing
Q_OBJECTmacro in your header, old qt4 connect syntax does not work without it.
alsoactionis wrong here as receiver object, it ought to bethisall 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 ); -
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.
-
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.
@vin212
seems like the compiler was unable to properly construct the polymorphism relationsMy bet would be because your only constructor
MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);requieres a pointer to an other instance of your class.
-
@vin212
seems like the compiler was unable to properly construct the polymorphism relationsMy bet would be because your only constructor
MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);requieres a pointer to an other instance of your class.
-
@vin212
seems like the compiler was unable to properly construct the polymorphism relationsMy bet would be because your only constructor
MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);requieres a pointer to an other instance of your class.
-
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.
@vin212 said in Slot and Signal problem custom class:
and i add Q_OBJECT
Regardless of any other issues. Any time you add
Q_OBJECTto 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 thevtableerror you got for that class. -
@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 answersAfter adding
Q_OBJECTto a class, you need rerun moc (Meta-Object Compiler).
Take a look at following links for more details!