Problem with connecting signals and slots with Qt (5), HELP please.
-
Hello I have a class:
@
class AjoutDefaut: public QDialog
{
Q_OBJECT
public
...
private:classDefaut* m_defaut;
...
private slots:
void beginProcess();
};
@and when I connect the beginProcess() with a signal(defined in classDefaut class) in AjoutDefaut.cpp
@ connect(m_defaut, SIGNAL(goProcess()), this, SLOT(beginProcess())); @
I have this error (when I write Q_OBJECT)
AjoutDefaut.obj:-1: erreur : LNK2001: symbole externe non résolu "public: virtual struct QMetaObject const * __cdecl AjoutDefaut::metaObject(void)const " (?metaObject@AjoutDefaut@@UEBAPEBUQMetaObject@@XZ)
AjoutDefaut.obj:-1: erreur : LNK2001: symbole externe non résolu "public: virtual void * __cdecl AjoutDefaut::qt_metacast(char const *)" (?qt_metacast@AjoutDefaut@@UEAAPEAXPEBD@Z)
AjoutDefaut.obj:-1: erreur : LNK2001: symbole externe non résolu "public: virtual int __cdecl AjoutDefaut::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@AjoutDefaut@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
AjoutDefaut.obj:-1: erreur : LNK2001: symbole externe non résolu "public: static struct QMetaObject const AjoutDefaut::staticMetaObject" (?staticMetaObject@AjoutDefaut@@2UQMetaObject@@B)
AND, if I COMMENT "Q_OBJECT" in DefautWidget class I get this Error:
QObject::connect: No such slot QDialog::beginProcess() in AjoutDefaut.cpp:132
I don't know how to resolve this BIG PROBLEM, I have been on this since this morning
Help please
Thank you
-
Hi,
When adding/removing Q_OBJECT, you need to re-run qmake before rebuilding (or rebuild from scratch).
-
Can you show the code from both classes ?
-
AjoutDefaut.h
@
#ifndef AJOUTDEFAUT_H ( There is a problem here, when I copied this line it was impossible, so I had to re-write it,
this line is not written like the others #ifndef in other classes in QtCreator, it has a different color, i don't know what kind of problem it is )
#define AJOUTDEFAUT_Hclass AjoutDefaut: public QDialog
{
Q_OBJECT
public:/*
- Constructeur */
AjoutDefaut();
private:
(...)
/*- Bouton pour la détection de contour /
QPushButton m_btn_cont;
/*
- Widget contenant l'image de base sur laquelle on colle les défauts */
classDefaut *m_classDefaut ;
private slots:
void gaussianfilter(QImage image);
void border_detect(QImage image);
void validate();
void beginProcess();
};
#endif AJOUTDEFAUT_H @AjoutDefaut.cpp
The constructor
@AjoutDefaut::AjoutDefaut()
{
(..)///> Connection des boutons avec les SLOT connect(m_classDefaut , SIGNAL(enableProcessing()), this, SLOT(beginProcess()));
(..)
}@Slot: beginProcess()
@void AjoutDefaut::beginProcess()
{
m_btn_cont->setEnabled(true);
QImage currentImage = *(m_dragWidgetCible->m_currentAnomaly);
connect(m_btn_cont, SIGNAL(clicked()), this, SLOT(border_detect(currentImage)));
}@ - Constructeur */
-
classDefaut.h file
@
#ifndef CLASSDEFAUT_H
#define CLASSDEFAUT_H#include (...)
QT_BEGIN_NAMESPACE
//class QDragEnterEvent;
class QDropEvent;
class QDragMoveEvent;
class QDragMoveEvent;
QT_END_NAMESPACE//! [0]
class classDefaut : public QFrame
{
Q_OBJECT
friend class AjoutDefaut;public:
...signals:
void enableProcessing();private slots:
void border_detect(QImage image);
void loadImage(QImage image);
};
//! [0]#endif // CLASSDEFAUT_H
@