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.