Nominate our 2022 Qt Champions!

[SOLVED] QTest example doesnt work

  • Hi all,
    I'm trying to follow QTest example here to make a unit test but it gives me this errors

    /home/aram/MEGA/proj/scratch/test/Qt_Test_Tutorial/tut_1/main.cpp:6: error: 
    undefined reference to `vtable for TestQString'

    My code is the same as it is in the example.
    I'm using Qt development environment from my distribution (opensuse leap 42.1)

  • Lifetime Qt Champion

    do you have Q_OBJECT
    in your class ?
    Try to delete the build folder.
    Then run qmake
    then rebuild all

  • of course i have... as i said, it just a copy

  • Lifetime Qt Champion

    also the
    #include "testqstring.moc"
    with the correct name ?
    #include "main.moc"
    (must match the file name)
    This will make the moc.exe tool run on the CPP file. Normally this
    tool only runs on .h files but Test unit are special and the include makes sure
    moc.ex is run on the file.
    The reason I ask is that the eror you get is very like what you get when moc.exe not been run on file.

  • @mrjj yes i had those things,,, i solved the problem by removing additional config lines (that qt_creator adds when you create a project) from *.pro file and left it only with

    QT += core testlib
    SOURCES += testfile.cpp

    and now it works...

  • Lifetime Qt Champion

    Ok. thanks for posting solution.

Log in to reply