PDA

View Full Version : Undefined Reference error!!!



Kapil
27th March 2006, 07:17
Hi,

I have used the Canvas Example and it is giving the following error when i run it:


release\imagezoomer.o(.text+0xe6e):imagezoomer.cpp : undefined reference to `ImageItem::hit(QPoint const&) const

the function which calls the hit function is :



void ImageZoomer::contentsMousePressEvent(QMouseEvent* e)
{
const QPoint p = inverseWorldMatrix().map(e->pos());
Q3CanvasItemList l=canvas->collisions(p);
for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
if ( (*it)->rtti() == ImageItem::imageRTTI ) {
ImageItem *item = (ImageItem*)(*it);
if ( !(item->hit(p)) )
continue;
}
moving = *it;
moving_start = p;
return;
}
moving = 0;
}


and the hit function is :

ImageItem.h


class ImageItem : public Q3CanvasRectangle
{
public:
//ImageItem();
ImageItem( QImage img, Q3Canvas *canvas );
int rtti () const { return imageRTTI; }
bool hit( const QPoint&) const;
static const int imageRTTI = 984376;

protected:
void drawShape( QPainter & );
private:
QImage image;
QPixmap pixmap;

};


ImageItem.cpp


bool ImageItem::hit( const QPoint &p ) const
{
int ix = p.x()-int(x());
int iy = p.y()-int(y());
if ( !image.valid( ix , iy ) )
return FALSE;
QRgb pixel = image.pixel( ix, iy );
return qAlpha( pixel ) != 0;
}

zlatko
27th March 2006, 08:24
emm..just imho try take const from declaration and implementation your method

p.s. and pls stop duplicate threads !

jpn
27th March 2006, 08:25
Have you


#include "imageitem.h"

in your imagezoomer.cpp?

Kapil
27th March 2006, 08:29
Have you


#include "imageitem.h"

in your imagezoomer.cpp?


hi jpn,

yes i have included the corresponding header file "imageitem.h" in my imagezoomer.cpp

kapil

Kapil
27th March 2006, 08:30
emm..just imho try take const from declaration and implementation your method

p.s. and pls stop duplicate threads !

Hi zlatko,

I have tried that also... by removing the const , does not remove the error.. i have tried all sorts of combinations but result being the same..

kapil

jpn
27th March 2006, 08:35
Do you have imageitem.cpp in your .pro file?
If not, add it, re-run qmake and rebuild..

Kapil
27th March 2006, 08:48
Do you have imageitem.cpp in your .pro file?
If not, add it, re-run qmake and rebuild..

Hi...

Thanks.. it now works...

But there is still no mouse action in it ????

zlatko
27th March 2006, 09:08
Have you declare Q_OBJECT

Kapil
27th March 2006, 09:50
Have you declare Q_OBJECT

yeaps...

Q_OBJECT is there...

Kapil
27th March 2006, 10:26
Hi...

what exactly the problem i am facing is that i am not able to intiate the mouse events.. my functions are not emitting any errors but mouse clicks or mouse moves are not being captured.. where to exactly intitiate them in the code so that the mouse movement gets recognized..

Kapil
27th March 2006, 11:15
hi,

i have re-implemented the mouseMoveEvent(QMouseEvent *event), mousePressEvent(QMouseEvent *event), mouseReleaseEvent(QMouseEvent *event)
and am just trying to pop-up a message box whenever the mouse moves over the widget but there is no response.. i went thru quite a few docs and also examples and all have done something similar to what i have done but there is still no response...

why is it so????

thanking you,
Kapil

zlatko
27th March 2006, 11:26
Have you declare this events handler in protected section ?

Kapil
27th March 2006, 11:34
Have you declare this events handler in protected section ?

yes,

they are declared in the protected section...

zlatko
27th March 2006, 11:40
So if i have undestand you we talk about ImageZoomer class?
Who is his parent?

Kapil
27th March 2006, 11:49
So if i have undestand you we talk about ImageZoomer class?
Who is his parent?

This class inherits the QMainWindow class and the header file for the class is :
ImageZoomer.h


class ImageZoomer : public QMainWindow
{
Q_OBJECT

public:
ImageZoomer(Ui::MainWindow *_mw);
~ImageZoomer();
void scaleImage(double factor);
void adjustScrollBar(QScrollBar *sbar, double factor);

protected:
void contentsMousePressEvent(QMouseEvent*);

public slots:

void open();
void zoomIn();
void zoomOut();
void zoomNormal();
void fitToWindow();

private:

QFrame *frame;
QScrollArea *sarea;
Q3ScrollView *sview;
double scalefactor;
Ui_MainWindow *mwin;
QPixmap fromImage;
Q3Canvas *canvas;
Q3CanvasView *canview;
QMouseEvent *mEvent;
Q3CanvasItem* moving;
QPoint moving_start;
QImage image;
};

zlatko
27th March 2006, 13:49
QMainWindow doesnt have slot void contentsMousePressEvent(QMouseEvent*);

Kapil
27th March 2006, 13:52
QMainWindow doesnt have slot void contentsMousePressEvent(QMouseEvent*);

Hi,

Okay.. This means that i will have to also inherit the class QCanvasView 'coz it contains the method contentsMousePressEvents(QMouseEvent *)...

Is it so?????

incubator
27th March 2006, 13:58
no, you just dont capture mouse events on a main window.

If you want to capture them in your canvas, make a class that extends QCanvas and override its mouse events.

Kapil
27th March 2006, 14:07
no, you just dont capture mouse events on a main window.

If you want to capture them in your canvas, make a class that extends QCanvas and override its mouse events.

Hi,

It means that i would make another class and its structure would look like this..


#include "imagezoomer.h"
class Sample : public QCanvas
{
public:
Sample();
protected:
void contentsMousePressEvent(QMouseEvent *);
private:
ImageZoomer *zoom;
};
Sample::Sample()
{
ImageZoomer zoom = new ImageZoomer;
}
void Sample::contentsMousePressEvent(QMouseEvent *event)
{
code
}


Is it so??????????????

incubator
27th March 2006, 14:23
sort of, but your ImageZoomer extends a main window, so that class should have a private member MyCanvas that extends a QCanvas (if you use Qt4 its Q3Canvas I think)

and in that MyCanvas class you override your mouse events.

Kapil
27th March 2006, 14:40
Hi...

The new class which i have created is CanvasMouse..

Now in my ImageZoomer i have created a CanvasMouse *canmouse variable which would call the CanvasMouse which inherits the Q3CanvasView....

In imageZoomer i have created a Q3CanvasView and have passed in the constructor of the CanvasMouse which reads this
CanvasMouse(Q3CanvasView *canview): canvasview(canview)

Now class CanvasMouse contains all the canvas related functionalities...

is this approach correct ?????

zlatko
27th March 2006, 15:17
In imageZoomer i have created a Q3CanvasView and have passed in the constructor of the CanvasMouse which reads this
CanvasMouse(Q3CanvasView *canview): canvasview(canview)


You sholdn't give Q3CanvasView parametr. You need give only pointer on parent class.



CanvasMouse *canmous = new CanvasMouse(this);

*****
CanvasMouse(ImageZoomer*p): canvasview(p)
{
}



p.s. also you could give any parametres (if you dont need it in future )

Kapil
28th March 2006, 05:09
You sholdn't give Q3CanvasView parametr. You need give only pointer on parent class.



CanvasMouse *canmous = new CanvasMouse(this);
*****
CanvasMouse(ImageZoomer*p): canvasview(p)
{
}



Hi..

won't this result in a circular dependency... i have included the header file "canmouse.h" in my ImageZoomer class and created an object of it.. Now when i pass the ImageZoomer object to CanMouse class, it would i suppose result into a circular dependency...

Isn't it so?????

incubator
28th March 2006, 09:02
yes, there is no need to pass the imagezoomer to your canvas, no need at all...
just have the canvas as member of imagezoomer and add this to one of your layouts

Kapil
28th March 2006, 09:07
yes, there is no need to pass the imagezoomer to your canvas, no need at all...
just have the canvas as member of imagezoomer and add this to one of your layouts

Hi...

i have done something similar but getting error
"Undefined reference to VTABLE" error.. I know this is inheritance problem but am not able to understand where i have gone wrong..

i have created a main.cpp where i create MainWindow object and pass it to ImageZoomer.cpp...
Now in ImageZoomer.cpp i have created CanvasMouse object and passed it the frame where i have to set the Canvas...
CanvasMouse derives the base class Q3CanvasView and in the constructor i have intialized the Q3CanvasView to frame.. The statement is:

CanvasMouse::CanvasMouse(QFrame *frame): Q3CanvasView(frame){}


But it is creating error.. what can be the possible reason behind it...

Kapil
28th March 2006, 12:03
Hi..

Done....

Thanks a lot everyone for all the suggestions provided....

Kapil