qt signal undefined reference error

qt signal undefined reference error

Asked on January 21, 2019 in Qt.
Add Comment


  • 10 Answer(s)

    The qt signal reference  to error:

           The class  begines to the  answer to  have the macro Q_OBJECT and  inherit the some QObject  to get.

    Answered on January 21, 2019.
    Add Comment

    The alternative answer is:

    They mention the answer to run the  qmake.

    Build > Run qmake
    
    

    By fixing the error.

    Answered on January 21, 2019.
    Add Comment

    When you are going to use Qt signals & slots mechanism you have to add Q_OBJECT macro in the top of definition of your class in order to generate correct moc_ code.
    add Q_OBJECT
    Clear your project
    Run qmake
    And only after that, run your project

    Answered on January 24, 2019.
    Add Comment

    #ifndef SERVER_H
    #define SERVER_H

    #include
    #include
    #include
    #include
    #include “../src/messages.h”

    class Server
    {
    public:
    Server();
    void start();
    private:
    void join(QString name);
    char buf[MSG_SIZE], msgSend[MSG_SIZE];
    QVector mq_external;
    QVector users;
    mqd_t mq_central;
    struct mq_attr attr;

    signals:
    void joined(QString name);

    };

    #endif // SERVER_H
    and this is my cpp file:

    Answered on January 27, 2019.
    Add Comment

    main.cpp
    @
    #include <QApplication>
    #include <QWidget>
    #include <QResizeEvent>
    #include “ExtDebug.h”

    class mwid : public QWidget{
    // the Q_OBJECT macro creates “undefined reference to vtable” errors
    //public:
    // Q_OBJECT
    signals:
    void mySizeChanged(int width, int height);

    public slots:
    void resizeEvent(QResizeEvent * ev){
    Q_UNUSED(ev);
    // if you remove next line, the rest of the code works just fine
    emit mySizeChanged(300, 200);
    }
    };

    int main(int argc, char *argv[]){
    QApplication app(argc, argv);

    mwid * mainWin = new mwid;
    mainWin->setMinimumSize(320, 240);
    ExtDebug * dbgWin = new ExtDebug(mainWin);

    mainWin->connect(mainWin, SIGNAL(mySizeChanged(int,int)),
    dbgWin, SLOT(resize(int,int)));

    mainWin->show();

    int ret = app.exec();

    delete mainWin;
    mainWin = nullptr;
    dbgWin = nullptr;

    return ret;
    }
    @

    ExtDebug.h
    @
    #ifndef EXTDEBUG_H
    #define EXTDEBUG_H

    #include <QObject>
    #include <QWidget>
    #include <QLineEdit>
    #include <QTextEdit>

    class ExtDebug : public QObject{
    public:

    QTextEdit * output;
    QLineEdit * input;

    ExtDebug(QWidget * parent);
    ~ExtDebug();

    public slots:
    void resize(int width, int height);
    };

    #endif // EXTDEBUG_H
    @

    ExtDebug.cpp
    @
    #include “ExtDebug.h”

    ExtDebug::ExtDebug(QWidget * parent){
    output = new QTextEdit(parent);
    output->setMinimumWidth(parent->minimumWidth());
    output->setMinimumHeight(parent->minimumHeight() – 20);
    output->move(0,0);

    input = new QLineEdit(parent);
    input->setMinimumWidth(parent->minimumWidth());
    input->setMinimumHeight(20);
    input->move(0, output->height());
    }

    ExtDebug::~ExtDebug(){
    delete input;
    delete output;

    input = nullptr;
    output = nullptr;
    }

    void ExtDebug::resize(int width, int height){
    output->resize(width, height – 20);

    input->resize(width, 20);
    input->move(0, height);
    }
    @

    Answered on January 28, 2019.
    Add Comment

    class ReadDPC: public QThread { //First edit: Q_OBJECT //End of first edit public: void run(); signals: void currentCount(int); };

    Answered on February 2, 2019.
    Add Comment
    class scene_mouse_event : public QGraphicsScene
    {
    
        Q_OBJECT
    
    public:
            scene_mouse_event(QObject* parent = 0);
    
            void mousePressEvent(QGraphicsSceneMouseEvent *event);
            QPointF pt;
    
    
    signals:
            void emit_mouse_pressed();
    
    
    };
    
    #endif // SCENE_MOUSE_EVENT_H
    Answered on February 4, 2019.
    Add Comment

    At the beginning of your class declaration you should have the macro Q_OBJECT and be sure to inherit from some QObject descendant.

    Apart from whatever is mentioned in this answer, also make sure to run qmake. i.e.:

    Build > Run qmake
    That should fix these errors.

    Answered on February 5, 2019.
    Add Comment

    They mention the answer to run the  qmake.

    1
    Build > Run qmake

    By fixing the error.

    Answered on February 5, 2019.
    Add Comment
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtGui>
    #include <QApplication>
    #include "scene_mouse_event.h"
    
    
    scene_mouse_event::scene_mouse_event(QObject* parent): QGraphicsScene(parent){
    
    }
    
    void scene_mouse_event::mousePressEvent(QGraphicsSceneMouseEvent *event)
    {
        this->pt = event->scenePos();
        emit emit_mouse_pressed();
        QGraphicsScene::mousePressEvent(event);
    }
    Answered on February 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.