Results 1 to 10 of 10

Thread: Undefined reference to my signal

  1. #1
    Join Date
    Jan 2006
    Location
    Poznań, Poland
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Undefined reference to my signal

    Hi!
    This is my first post so I'd like to say hello everyone!
    I am trying to compile my simple project, but I get an error:
    Qt Code:
    1. release\fetchThread.o(.text+0x387):fetchThread.cpp: undefined reference to `FetchThread::log(QString)'
    2. release\fetchThread.o(.text+0x3ba):fetchThread.cpp: undefined reference to `FetchThread::connected()'
    3. collect2: ld returned 1 exit status
    4. mingw32-make[1]: *** [release\project.exe] Error 1
    To copy to clipboard, switch view to plain text mode 
    FetchThread::log(QString) and FetchThread::connected(void) are my own signals defined in the appropriate header file.
    Files:
    PROJECT DIRECTORY
    WRONG CPP
    WRONG H
    It complains about my signals emitted from the above CPP file.
    Please help
    Regards,
    Tomek

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to my signal

    It looks like make didn't run moc program on your fetchThread.h file. Run qmake (without any parameters) to generate new Makefiles and try compiling your project again.

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

    Default Re: Undefined reference to my signal

    Add HEADERS+=fetchThread.h to your .pro file.

  4. #4
    Join Date
    Jan 2006
    Location
    Poznań, Poland
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Undefined reference to my signal

    Thank you! It works now.
    First I added the HEADERS directive and then generated new Makefiles.
    Happy New Year

  5. #5
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Red face Re: Undefined reference to my signal

    I can't tell you how many times I have been banging my head on the desk asking myself "why isn't this compiling?!?" then realizing I need to run qmake again because I added another file to the project since last time I ran it.
    (of course this is AFTER I go through all of the source code, like, 5 times lol)

    Katrina

  6. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Undefined reference to my signal

    AFAIK. If you add a file then make calls qmake first. Only when u add Q_OBJECT to the class do we need to call the qmake manually.
    We can't solve problems by using the same kind of thinking we used when we created them

  7. The following user says thank you to sunil.thaha for this useful post:

    PstdEr (23rd July 2013)

  8. #7
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    16
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Undefined reference to my signal

    btw, there is a strange symbol (single quote) after "HEADERS" in the project file

  9. #8
    Join Date
    Jan 2006
    Location
    Poznań, Poland
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: Undefined reference to my signal

    I found the apostrophe too, happily quickly
    I've been always executing `qmake && make` not to forget about the qmake.
    Thanks for your posts!

  10. #9
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    64
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile Re: Undefined reference to my signal

    Quote Originally Posted by sunil.thaha
    Only when u add Q_OBJECT to the class do we need to call the qmake manually.
    This is good to know, I have been trying to run it after I add any new file regardless of of it Q_OBJECT-ed-ness. (although I tend to implement signals and slots heavily(maybe too much so!), so 80% of my new code is a Q_OBJECT...still good info!!! Thanks!)

    Katrina

  11. #10
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: Undefined reference to my signal

    Missing Q_OBJECT in the class declaration also does lead to the same error: undefined reference to `MyThread::MySignal()'

  12. The following user says thank you to TheIndependentAquarius for this useful post:

    PstdEr (23rd July 2013)

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.