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. Problem with connecting signals and slots with Qt (5), HELP please.
Forum Updated to NodeBB v4.3 + New Features

Problem with connecting signals and slots with Qt (5), HELP please.

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.6k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    timain
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          timain
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • T Offline
              T Offline
              timain
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Can you show the code from both classes ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  timain
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    timain
                    wrote on last edited by
                    #9

                    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
                    @

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      timain
                      wrote on last edited by
                      #10

                      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

                      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