PDA

View Full Version : undefined reference to `vtable for ... ', specific for QT projects...



jiapei100
7th January 2010, 17:29
Seriously have no idea why this happens, particularly, always happening in QT projects.



../utils/bin/Debug/libutils.a(ImageView.o): In function `CImageView':
/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:13: undefined reference to `vtable for CImageView'
/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:13: undefined reference to `vtable for CImageView'
/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:13: undefined reference to `vtable for CImageView'
/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:13: undefined reference to `vtable for CImageView'
../utils/bin/Debug/libutils.a(ImageView.o): In function `~CImageView':
/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:23: undefined reference to `vtable for CImageView'
../utils/bin/Debug/libutils.a(ImageView.o):/home/jiapei/MyPrograms/codeblocks/aam/utils/src/ImageView.cpp:23: more undefined references to `vtable for CImageView' follow
collect2: ld returned 1 exit status
make: *** [objdetection] Error 1



It seems to tell than CImageView is missing something .

My CImageView is defined as:




#ifndef __IMAGEVIEW_QT__
#define __IMAGEVIEW_QT__

#include <QGraphicsView>
#include <QLabel>
#include <QBoxLayout>


#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

/**
show an image in the corresponding wxWindow
*/
class CImageView : public QGraphicsView
{
Q_OBJECT

private:
bool m_isDrawing;
QGraphicsScene* m_QTScene;
QImage* m_QTImage;
protected:
void paintEvent(QPaintEvent *event);

public:
CImageView( QWidget *parent = 0 );
virtual ~CImageView( );

//CImageView& operator=(const CImageView& iImgView);

void putImage(const Mat& image);
};

#endif // __IMAGEVIEW_QT__



And, I'm pretty sure that none of the functions is not defines.
Namely, all declared functions have been defined in .cpp files !!!!

So, the only possibility is " QGraphicsView " is not defined.


Am I correct? How to avoid such error messages ?

Please do help !!!

Best Regards
JIA

wysota
7th January 2010, 18:24
Rerun qmake after adding the Q_OBJECT macro to an existing file and make sure all virtual methods that are declared, are also implemeneted.

jiapei100
8th January 2010, 11:05
Yes, as you might have seen in my header file



#ifndef __IMAGEVIEW_QT__
#define __IMAGEVIEW_QT__

#include <QGraphicsView>
#include <QLabel>
#include <QBoxLayout>


#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

/**
show an image in the corresponding wxWindow
*/
class CImageView : public QGraphicsView
{
Q_OBJECT // declared !!!!!!!!!

private:
bool m_isDrawing;
QGraphicsScene* m_QTScene;
QImage* m_QTImage;
protected:
void paintEvent(QPaintEvent *event);

public:
CImageView( QWidget *parent = 0 );
virtual ~CImageView( );

//CImageView& operator=(const CImageView& iImgView);

void putImage(const Mat& image);
};

#endif // __IMAGEVIEW_QT__




What's more, the only virtual function (destructor) has been absolutely defined in the .cpp file as:


CImageView::~CImageView( )
{
if(this->m_QTImage) delete (this->m_QTImage);
if(this->m_QTScene) delete (this->m_QTScene);
}


Why QT always brings such kind of weird error messages, while other projects don't ?
Any more detailed explanation what's actually happening inside QT project that might have caused this?


Cheers
JIA




Rerun qmake after adding the Q_OBJECT macro to an existing file and make sure all virtual methods that are declared, are also implemeneted.

wysota
8th January 2010, 11:26
Yes, as you might have seen in my header file
I asked you if you ran qmake after setting the macro and not if you declared it.


Why QT always brings such kind of weird error messages, while other projects don't ?
Ask Apple, QuickTime is their product.