Results 1 to 4 of 4

Thread: Linking issues with emiting a custom signal from a QGraphicsScene subclass?

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Linking issues with emiting a custom signal from a QGraphicsScene subclass?

    Hi, I am trying to emit a signal from a custom subclass of QGraphicsScene. I get the following errors:
    Qt Code:
    1. "BoardScene::selected(int)", referenced from:
    2. BoardScene::select(int) in boardscene.o
    3. ld: symbol(s) not found
    4. collect2: ld returned 1 exit status
    5. make: *** [Msg.app/Contents/MacOS/Msg] Error 1
    6. make: Leaving directory `/Users/tom/Documents/Qt/Msg-build-desktop'
    7. The process "/usr/bin/make" exited with code 2.
    8. Error while building project Msg (target: Desktop)
    9. When executing build step 'Make'
    To copy to clipboard, switch view to plain text mode 

    Why am I getting this error? What I want is that when a GraphicsPin is clicked, that it notifies the BoardScene (through bs->select(num)) of a click and then BoardScene emits the selected(num) signal.

    boardscene.h:


    Qt Code:
    1. #ifndef BOARDSCENE_H
    2. #define BOARDSCENE_H
    3. #include <QGraphicsScene>
    4. #include <QGraphicsItem>
    5.  
    6.  
    7. class BoardScene;
    8.  
    9. class GraphicsPin : public QGraphicsRectItem
    10. {
    11.  
    12. public:
    13. GraphicsPin();
    14. ~GraphicsPin();
    15. void set(BoardScene* bs, int num,qreal x, qreal y,qreal size);
    16. private:
    17. int num;
    18. QPen pen;
    19. QBrush brush;
    20. BoardScene* bs;
    21. protected :
    22. void hoverEnterEvent ( QGraphicsSceneHoverEvent * event );
    23. void mousePressEvent ( QGraphicsSceneMouseEvent * event );
    24.  
    25.  
    26.  
    27. };
    28.  
    29. class BoardScene : public QGraphicsScene
    30. {
    31. // Should I put Q_OBJECT here?
    32. //Q_OBJECT
    33.  
    34.  
    35. public:
    36. BoardScene();
    37. ~BoardScene();
    38. protected:
    39. QPixmap pixmap;
    40. void load(QString file);
    41. void addPin(int num, qreal x, qreal y);
    42. int pinSize;
    43. GraphicsPin graphicsPin[128];
    44. int pins;
    45. int selectedPin;
    46.  
    47. private:
    48. QPen penNone;
    49. QBrush brushNone;
    50. signals:
    51. void selected(int num);
    52.  
    53.  
    54. public slots:
    55. void select(int num);
    56. };
    57.  
    58.  
    59.  
    60. #endif // BOARDSCENE_H
    To copy to clipboard, switch view to plain text mode 



    boardscene.cpp:

    Qt Code:
    1. #include "boardscene.h"
    2. #include "qdebug.h"
    3.  
    4. ////// GRAPHICSPIN //////
    5.  
    6. GraphicsPin::GraphicsPin() {
    7. setAcceptHoverEvents(true);
    8. pen.setStyle(Qt::SolidLine);
    9. pen.setWidth(1);
    10. pen.setBrush(QColor(255,255,255));
    11. brush.setStyle(Qt::SolidPattern);
    12. brush.setColor(QColor(255,255,255));
    13.  
    14. setPen(pen);
    15. setBrush(brush);
    16. }
    17.  
    18. GraphicsPin::~GraphicsPin() {
    19.  
    20. }
    21.  
    22. void GraphicsPin::set(BoardScene *bs,int num,qreal x, qreal y,qreal size) {
    23. setRect(x,y,size,size);
    24. this->num = num;
    25. this->bs = bs;
    26. }
    27.  
    28. void GraphicsPin::hoverEnterEvent ( QGraphicsSceneHoverEvent * event ) {
    29. qDebug() << "GraphicsPin::hoverEnterEvent";
    30. }
    31.  
    32. void GraphicsPin::mousePressEvent(QGraphicsSceneMouseEvent * event ) {
    33. qDebug() << "GraphicsPin::mousePressEvent";
    34. if ( bs ) bs->select(num);
    35.  
    36. }
    37.  
    38. ////// BOARDSCENE //////
    39.  
    40. BoardScene::BoardScene()
    41. {
    42.  
    43. addItem(&board);
    44. selectedPin = -1;
    45.  
    46. }
    47.  
    48.  
    49. BoardScene::~BoardScene() {
    50.  
    51. }
    52.  
    53.  
    54. void BoardScene::select(int num) {
    55. if ( num != selectedPin ) {
    56. qDebug() << "BoardScene::select" << num;
    57. selectedPin = num;
    58. emit selected(num);
    59. }
    60. }
    61.  
    62. void BoardScene::load(QString file) {
    63. pixmap.load(file);
    64. board.setPixmap(pixmap);
    65.  
    66. }
    67.  
    68. void BoardScene::addPin(int num, qreal x, qreal y) {
    69. graphicsPin[num].set(this,num,x,y,pinSize);
    70. addItem(&graphicsPin[num]);
    71. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help.
    Last edited by wysota; 31st August 2011 at 22:39.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Linking issues with emiting a custom signal from a QGraphicsScene subclass?

    You are missing the Q_OBJECT macro in your scene class.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Linking issues with emiting a custom signal from a QGraphicsScene subclass?

    Quote Originally Posted by wysota View Post
    You are missing the Q_OBJECT macro in your scene class.
    With the macro I get even more errors:
    Qt Code:
    1. Undefined symbols:
    2. "vtable for BoardScene", referenced from:
    3. BoardScene::~BoardScene()in boardscene.o
    4. BoardScene::~BoardScene()in boardscene.o
    5. BoardScene::~BoardScene()in boardscene.o
    6. BoardScene::BoardScene()in boardscene.o
    7. BoardScene::BoardScene()in boardscene.o
    8. "BoardScene::selected(int)", referenced from:
    9. BoardScene::select(int) in boardscene.o
    10. ld: symbol(s) not found
    11. collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 


    Added after 15 minutes:


    I removed a class that I was conflicting with the build. Everything works now, thanks!
    Last edited by mrtof; 1st September 2011 at 06:57.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking issues with emiting a custom signal from a QGraphicsScene subclass?

    Re-run qmake and then rebuild so that moc is run.

Similar Threads

  1. problem with emiting a signal
    By msmihai in forum Newbie
    Replies: 2
    Last Post: 3rd January 2009, 14:32
  2. QDateEdit emiting signal problem
    By anafor2004 in forum Newbie
    Replies: 1
    Last Post: 17th June 2008, 07:59
  3. not emiting signal
    By bisz in forum Newbie
    Replies: 4
    Last Post: 3rd October 2007, 07:49
  4. Problem emiting signal in QTreeWidgetItem's subclass
    By Shawn in forum Qt Programming
    Replies: 12
    Last Post: 4th September 2007, 12:08
  5. Emiting signal, which NOT connected to any slots
    By krivenok in forum Qt Programming
    Replies: 7
    Last Post: 27th February 2006, 16:32

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
  •  
Qt is a trademark of The Qt Company.