Qt World Summit: Submit your Presentation


Google test and QObject derived object. Errors



  • I get errors when trying testing with Google Test the QObject derived class - QCat test class.

    undefined reference to `QCat::QCat(QObject*)'
    
    undefined reference to `vtable for QCat'
    

    the code:
    GitHub

    I Include the QCat headers from main project to project for testing in order to create tests fo QCat. All come across is solution to run QMake whick did not work in this case.
    Please help with this issue.





  • Looking at your partial code...

    Where is qcat.h ?

    Your error out at

    QCat cat;

    Just guessing but is the class name named "QCat" exactly ?

    Or is it "Qcat" or "qCat" ?

    Post qcat.h for more help.



  • @EatonCode class name is QCat
    full code is acceesible by Link GitHub in first post.





  • @Kofr Usually this happens when your object has not been moc'd. Assuming your google test is a separate build (since they usually are), you do not have the proper build for your object.

    Which is why the solution proposed online is "run qmake". Because normally qmake would properly moc your object.

    Edit: Investigated a bit further, here is your project file for the test:

    
    include(../gtest_dependency.pri)
    
    TEMPLATE = app
    CONFIG += console c++11
    CONFIG -= app_bundle
    CONFIG += thread
    CONFIG += qt
    
    HEADERS +=     tst_isvalueok.h
    
    SOURCES +=     main.cpp
    
    # added this in order to be able to include "cat.h"
    INCLUDEPATH += ../../../src
    

    Nowhere in there does it link to a library containing qcat or include the object for qcat. So as stated earlier, your build is broken. ;)

    If you're still having trouble I can fix it for you later on. I'm not on a system with a development environment right now.



  • @ambershark solved

    
    include(../gtest_dependency.pri)
    SRC_DIR = ../../../src
    
    TEMPLATE = app
    CONFIG += console c++11
    CONFIG -= app_bundle
    CONFIG += thread
    CONFIG += qt
    
    
    HEADERS +=     tst_isvalueok.h \
                   $$SRC_DIR/qcat.h
    
    SOURCES +=     main.cpp \
                   $$SRC_DIR/qcat.cpp
    
    
    # added this in order to be able to include "qcat.h"
    INCLUDEPATH += $$SRC_DIR
    
    ```


  • Good to hear! Don't forget to mark as solved for anyone else with the same problem. :)


Log in to reply