[Solved] Problem with Q_OBJECT



  • I have such a class myLabel:

    header:
    @#ifndef MYLABEL_H
    #define MYLABEL_H
    #include <QLabel>
    #include <QObject>

    class myLabel : public QLabel
    {
    //Q_OBJECT - when i uncomment it coompilator show me: undefined reference to 'vtable for myLabel'

    public:
    myLabel();
    bool flag_grid;

    private:
    //bool flag_grid;
    bool flag_markers;

    protected:
    void paintEvent(QPaintEvent *e);
    };

    #endif // MYLABEL_H@

    source file:
    @#include "myLabel.h"
    #include <QPainterPath>
    #include <QPainter>
    #include <QLabel>
    #include <QPixmap>

    myLabel::myLabel()
    {

    }
    do
    void myLabel::paintEvent(QPaintEvent *e){

    }@

    I would like to have a slots in this class but without Q_OBJECT it's impossible what i should add to this code to make it run??



  • have you tried running qmake after adding Q_OBJECT?



  • when i add Q_OBJECT to my header the compilator show me:
    undefined reference to 'vtable for myLabel'
    collect2: ld returned 1 exit status



  • You can solve the problem if delete the folder where Qt save object files, and then recompile your project.
    In my case the folder has name "projectName-build-desktop".



  • i think it helped, but it's a little bit strange. In a minute i will do a slot and check this, but now it is compiling without any errors. Thanks a lot



  • it's work, once again thank You



  • You are welcome :-)



  • As it was suggested you don't need to delete something by hands. Rerunning qmake (not compiler) should help you.
    And if problem is solved don't forget to mark it as [solved].



  • Hey Denis, i know it's stupid question but where i should click to mark this thread as solved?? I don't see such option...
    [quote author="Denis Kormalev" date="1306694082"]As it was suggested you don't need to delete something by hands. Rerunning qmake (not compiler) should help you.
    And if problem is solved don't forget to mark it as [solved].[/quote]



  • Simply edit your first post and add [solved] to title (better add it to beginning not to end of title)



  • @Denis Kormalev: Oh, run qmake again work. I'm deleting folder by hands, because think that if i recompile all it call qmake too.
    @kamilus just edit your post and add to begin [solved]


Log in to reply
 

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