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


  • Lifetime Qt Champion

    Hi,

    When adding/removing Q_OBJECT, you need to re-run qmake before rebuilding (or rebuild from scratch).



  • Hmmm, perhaps your classDefaut class does not inherit from QObject?



  • Hi,
    Thank's for reply,
    I re-runned QMake and *classDefaut * inherits from QFrame, And I use Q_OBJECT within it.

    I specify that if I replace SLOT(beginProcess()) by SLOT(close()) or something else it works...



  • Ok, another guess: your AjoutDefaut class definition, is it in an .h file?



  • Yes, it is. And I call connect(..) function at the constructor in .cpp file.


  • Lifetime Qt Champion

    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_H

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



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



  • Problem fixed, I deleted AjoutDefaut.h, re-created it and include the new file with the same contain in my project (there was a problem with this file so moc object cannot be created when I use Q_OBJECT).

    Thank you all


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.