Results 1 to 3 of 3

Thread: Qt signal error : undefined reference to 'FramesEditor::setNewActiveFrame(Frame *)' ?

  1. #1
    Join Date
    Jan 2018
    Location
    India, Delhi
    Posts
    10
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Qt signal error : undefined reference to 'FramesEditor::setNewActiveFrame(Frame *)' ?

    I'm making a simple animation software, cutting it short, basically, i have made few classes out of which
    FrameManager class manages animation frames (inside a QMap<int, Frame*> )
    FramesEditor class inherits QGraphicsView and is used to view current active frame ( QGraphicsScene)

    These classes are all implemented using singleton design pattern, however, im facing issue when defining connection only between FrameManager and FramesEditor instances

    in FrameManager class
    Qt Code:
    1. void FrameManager::setCurrentActiveFrame(int frameID)
    2. {
    3. qDebug()<<">>> frameManager.cpp : currentActiveFrame ID : "<<currentActiveFrame;
    4. Frame *activeFrame = frameBank[keyStartFrame];
    5.  
    6. if(frameBank.contains(frameID)){
    7. currentActiveFrame = frameID;
    8. activeFrame = frameBank[currentActiveFrame];
    9. }
    10. qDebug()<<">>> frameManager.cpp : currentActiveFrame ID updated: "<<currentActiveFrame;
    11.  
    12. emit (FramesEditor::getInstance())->setNewActiveFrame(activeFrame); //causing error
    13. }
    To copy to clipboard, switch view to plain text mode 

    the last line where im emitting the signal, it is causing the issue
    Qt Code:
    1. E:\GITHUB_REPOSITORIES\ProtoAnimator\protoanimator\framemanager.cpp:74: error: undefined reference to `FramesEditor::setNewActiveFrame(Frame*)'
    To copy to clipboard, switch view to plain text mode 

    I've checked everything such as including frameseditor.h header and related files but could not figure out why is this happening

    in case you need more code, here is how im defining connections

    I have 3 classes (singleton)
    1. Manager (this class is acting as a communication handler between other 2 manager classes)
    2. FrameManager
    3. SpriteManager

    the manager class is acting as a central class that is initialized first
    inside it's constructor, i have one of the connection
    Qt Code:
    1. connect(FramesEditor::getInstance(), SIGNAL(setNewActiveFrame(Frame*)), FramesEditor::getInstance(), SLOT(renderFrame(Frame*)));
    To copy to clipboard, switch view to plain text mode 

    note that renderFrame(Frame*) simply calls setScene() method

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt signal error : undefined reference to 'FramesEditor::setNewActiveFrame(Frame *

    I don't have the time to look at the emit implmentation, but I don't think emit can do what your code is telling it.
    As far as I know, emit needs a signature of an empty method defined as a signal (that moc then translates to calls in an meta object).

    One why to do it is to wrap the signal emitting in your singleton:
    Something like this:
    Qt Code:
    1. void FramesEditor::emitSetNewActiveFrame(Frame *frame){
    2. emit setNewActiveFrame(frame);
    3. }
    To copy to clipboard, switch view to plain text mode 

    and in the using code:

    Qt Code:
    1. void FrameManager::setCurrentActiveFrame(int frameID)
    2. {
    3. qDebug()<<">>> frameManager.cpp : currentActiveFrame ID : "<<currentActiveFrame;
    4. Frame *activeFrame = frameBank[keyStartFrame];
    5.  
    6. if(frameBank.contains(frameID)){
    7. currentActiveFrame = frameID;
    8. activeFrame = frameBank[currentActiveFrame];
    9. }
    10. qDebug()<<">>> frameManager.cpp : currentActiveFrame ID updated: "<<currentActiveFrame;
    11.  
    12. //emit (FramesEditor::getInstance())->setNewActiveFrame(activeFrame); //causing error
    13. FramesEditor::getInstance()->emitSetNewActiveFrame(activeFrame);
    14. }
    To copy to clipboard, switch view to plain text mode 

    You will also need to update your connect().
    But there is also a deisgn issue here.
    You are emitting a signal defined in FramesEditor from FrameManager, which is possible as I have shown but points to a design flaw.
    Since signals are only messages, they should be defined by the signaling object.
    So I don't see why this signal is defined in FramesEditor and not in FrameManager.
    That is probably the best line of action - move the signal to FrameManager since it is the class actually emitting the signal.
    Last edited by high_flyer; 1st March 2018 at 12:02.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    keshav2010 (1st March 2018)

  4. #3
    Join Date
    Jan 2018
    Location
    India, Delhi
    Posts
    10
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt signal error : undefined reference to 'FramesEditor::setNewActiveFrame(Frame *

    Thanks for pointing out the design flaw, and also updated connect to a newer syntax. That fixed the issue

Similar Threads

  1. Android undefined reference to signal,sigfillset,stpcpy...
    By sifourquier in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 15th August 2016, 16:02
  2. Replies: 2
    Last Post: 11th August 2012, 18:37
  3. Undefined reference to signal
    By chinalski in forum Qwt
    Replies: 8
    Last Post: 29th July 2012, 20:05
  4. Undefined reference to my signal
    By tomek in forum Newbie
    Replies: 9
    Last Post: 1st December 2011, 08:14
  5. Undefined Reference error!!!
    By Kapil in forum Newbie
    Replies: 25
    Last Post: 28th March 2006, 13:03

Tags for this Thread

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.