-
Undefined Reference error!!!
Hi,
I have used the Canvas Example and it is giving the following error when i run it:
[HTML]release\imagezoomer.o(.text+0xe6e):imagezoomer.cpp : undefined reference to `ImageItem::hit(QPoint const&) const[/HTML]
the function which calls the hit function is :
Code:
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
Code:
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:
private:
};
ImageItem.cpp
Code:
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;
}
-
Re: Undefined Reference error!!!
emm..just imho try take const from declaration and implementation your method
p.s. and pls stop duplicate threads !
-
Re: Undefined Reference error!!!
Have you
Code:
#include "imageitem.h"
in your imagezoomer.cpp?
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by jpn
Have you
Code:
#include "imageitem.h"
in your imagezoomer.cpp?
hi jpn,
yes i have included the corresponding header file "imageitem.h" in my imagezoomer.cpp
kapil
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
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
-
Re: Undefined Reference error!!!
Do you have imageitem.cpp in your .pro file?
If not, add it, re-run qmake and rebuild..
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by jpn
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 ????
-
Re: Undefined Reference error!!!
Have you declare Q_OBJECT
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
Have you declare Q_OBJECT
yeaps...
Q_OBJECT is there...
-
Re: Undefined Reference error!!!
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..
-
Re: Undefined Reference error!!!
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
-
Re: Undefined Reference error!!!
Have you declare this events handler in protected section ?
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
Have you declare this events handler in protected section ?
yes,
they are declared in the protected section...
-
Re: Undefined Reference error!!!
So if i have undestand you we talk about ImageZoomer class?
Who is his parent?
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
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
Code:
{
Q_OBJECT
public:
ImageZoomer(Ui::MainWindow *_mw);
~ImageZoomer();
void scaleImage(double factor);
void adjustScrollBar
(QScrollBar *sbar,
double factor
);
protected:
public slots:
void open();
void zoomIn();
void zoomOut();
void zoomNormal();
void fitToWindow();
private:
Q3ScrollView *sview;
double scalefactor;
Ui_MainWindow *mwin;
Q3Canvas *canvas;
Q3CanvasView *canview;
Q3CanvasItem* moving;
};
-
Re: Undefined Reference error!!!
QMainWindow doesnt have slot void contentsMousePressEvent(QMouseEvent*);
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
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?????
-
Re: Undefined Reference error!!!
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.
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by incubator
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..
[HTML]
#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
}
[/HTML]
Is it so??????????????
-
Re: Undefined Reference error!!!
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.
-
Re: Undefined Reference error!!!
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 ?????
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by Kapil
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.
Code:
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 )
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by zlatko
You sholdn't give Q3CanvasView parametr. You need give only pointer on parent class.
Code:
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?????
-
Re: Undefined Reference error!!!
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
-
Re: Undefined Reference error!!!
Quote:
Originally Posted by incubator
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...
-
Re: Undefined Reference error!!!
Hi..
Done....
Thanks a lot everyone for all the suggestions provided....
Kapil