+ Reply to Thread
Results 1 to 1 of 1

Thread: QT Unit Testing moc problem "unresolved external symbol" for QMetaObject

  1. #1
    Join Date
    Jul 2015
    Qt products
    Unix/X11 Windows

    Default QT Unit Testing moc problem "unresolved external symbol" for QMetaObject

    I'm trying to add unit tests to a project of mine for the first time.

    I can run mock tests alright (without using my project's classes) and run the application alright. But if I instantiate objects from the project I get an unresolved external symbol of the QMetaObject. If I recall correctly, this means the moc of the object isn't being included on the project.

    How do I fix this? I have the same issue using googletests. The guide also doesn't help on this. I've tried installing the qt unit testing plugin, same result.

    I've uploaded a mock project that follows the same structure that I'm using in the aforementioned project, fetch it here: https://github.com/quimnuss/QtUnitTestingTest

    I'm using a static build of qt on windows, but I guess that's irrellevant. Using QtCreator as IDE and NMAke build.

    I've also tried add the HelloWorld.lib, but taking a look at the Makefile.release it isn't used.

    Somebody has an idea of what I'm doing wrong?

    Here's the unit testing .pro:
    Qt Code:
    1. QT += widgets network testlib
    3. TARGET = tst_someunittesttest
    4. CONFIG += console
    5. CONFIG -= app_bundle
    7. TEMPLATE = app
    9. INCLUDEPATH += $$PWD/../HelloWorld
    11. include($$PWD/../HelloWorld/helloworldCommon.pri)
    13. LIBS += -L"$$OUT_PWD/../HelloWorld/release"
    14. LIBS += -lHelloWorld
    16. message("Searching libs here $$LIBS")
    18. SOURCES += tst_someunittesttest.cpp
    19. DEFINES += SRCDIR=\\\"$$PWD/\\\"
    To copy to clipboard, switch view to plain text mode 

    The first error's complete message:

    Qt Code:
    1. tst_someunittesttest.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl HelloWorld::metaObject(void)const " (?metaObject@HelloWorld@@UEBAPEBUQMetaObject@@XZ)
    To copy to clipboard, switch view to plain text mode 
    Last edited by quimnuss; 6th January 2017 at 17:53.

+ Reply to Thread

Similar Threads

  1. Replies: 4
    Last Post: 9th May 2016, 13:30
  2. Replies: 1
    Last Post: 25th February 2016, 18:17
  3. Replies: 11
    Last Post: 13th August 2012, 18:15
  4. Replies: 4
    Last Post: 5th January 2011, 16:51
  5. Unresolved external symbol "staticMetaObject"
    By sr71 in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2010, 00:26


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts