Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: Undefined Reference error!!!

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 :

    Qt Code:
    1. void ImageZoomer::contentsMousePressEvent(QMouseEvent* e)
    2. {
    3. const QPoint p = inverseWorldMatrix().map(e->pos());
    4. Q3CanvasItemList l=canvas->collisions(p);
    5. for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
    6. if ( (*it)->rtti() == ImageItem::imageRTTI ) {
    7. ImageItem *item = (ImageItem*)(*it);
    8. if ( !(item->hit(p)) )
    9. continue;
    10. }
    11. moving = *it;
    12. moving_start = p;
    13. return;
    14. }
    15. moving = 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    and the hit function is :

    ImageItem.h
    Qt Code:
    1. class ImageItem : public Q3CanvasRectangle
    2. {
    3. public:
    4. //ImageItem();
    5. ImageItem( QImage img, Q3Canvas *canvas );
    6. int rtti () const { return imageRTTI; }
    7. bool hit( const QPoint&) const;
    8. static const int imageRTTI = 984376;
    9.  
    10. protected:
    11. void drawShape( QPainter & );
    12. private:
    13. QImage image;
    14. QPixmap pixmap;
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    ImageItem.cpp
    Qt Code:
    1. bool ImageItem::hit( const QPoint &p ) const
    2. {
    3. int ix = p.x()-int(x());
    4. int iy = p.y()-int(y());
    5. if ( !image.valid( ix , iy ) )
    6. return FALSE;
    7. QRgb pixel = image.pixel( ix, iy );
    8. return qAlpha( pixel ) != 0;
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Undefined Reference error!!!

    emm..just imho try take const from declaration and implementation your method

    p.s. and pls stop duplicate threads !
    Last edited by zlatko; 27th March 2006 at 08:29.
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Undefined Reference error!!!

    Have you
    Qt Code:
    1. #include "imageitem.h"
    To copy to clipboard, switch view to plain text mode 
    in your imagezoomer.cpp?

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined Reference error!!!

    Quote Originally Posted by jpn
    Have you
    Qt Code:
    1. #include "imageitem.h"
    To copy to clipboard, switch view to plain text mode 
    in your imagezoomer.cpp?

    hi jpn,

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

    kapil

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Undefined Reference error!!!

    Do you have imageitem.cpp in your .pro file?
    If not, add it, re-run qmake and rebuild..

  7. #7
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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 ????

  8. #8
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Undefined Reference error!!!

    Have you declare Q_OBJECT
    a life without programming is like an empty bottle

  9. #9
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined Reference error!!!

    Quote Originally Posted by zlatko
    Have you declare Q_OBJECT
    yeaps...

    Q_OBJECT is there...

  10. #10
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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..

  11. #11
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  12. #12
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Undefined Reference error!!!

    Have you declare this events handler in protected section ?
    a life without programming is like an empty bottle

  13. #13
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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...

  14. #14
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Undefined Reference error!!!

    So if i have undestand you we talk about ImageZoomer class?
    Who is his parent?
    a life without programming is like an empty bottle

  15. #15
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. class ImageZoomer : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. ImageZoomer(Ui::MainWindow *_mw);
    7. ~ImageZoomer();
    8. void scaleImage(double factor);
    9. void adjustScrollBar(QScrollBar *sbar, double factor);
    10.  
    11. protected:
    12. void contentsMousePressEvent(QMouseEvent*);
    13.  
    14. public slots:
    15.  
    16. void open();
    17. void zoomIn();
    18. void zoomOut();
    19. void zoomNormal();
    20. void fitToWindow();
    21.  
    22. private:
    23.  
    24. QFrame *frame;
    25. QScrollArea *sarea;
    26. Q3ScrollView *sview;
    27. double scalefactor;
    28. Ui_MainWindow *mwin;
    29. QPixmap fromImage;
    30. Q3Canvas *canvas;
    31. Q3CanvasView *canview;
    32. QMouseEvent *mEvent;
    33. Q3CanvasItem* moving;
    34. QPoint moving_start;
    35. QImage image;
    36. };
    To copy to clipboard, switch view to plain text mode 

  16. #16
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Undefined Reference error!!!

    QMainWindow doesnt have slot void contentsMousePressEvent(QMouseEvent*);
    a life without programming is like an empty bottle

  17. #17
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?????

  18. #18
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  19. #19
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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??????????????

  20. #20
    Join Date
    Mar 2006
    Posts
    10
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

Similar Threads

  1. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  2. MS Sql native driver??
    By LordQt in forum Qt Programming
    Replies: 4
    Last Post: 9th October 2007, 13:41
  3. error undefined reference ...............
    By amit_pansuria in forum Qt Programming
    Replies: 2
    Last Post: 8th June 2007, 14:28
  4. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  5. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 19:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.