This question already has an answer here:
- Include a .pro file in Qt? 1 answer
I just don't understand what is the overall layout of a Qt project with a program and a test...
The project of QTest tutorial only have the test program, but my project already have another program. If I add the test case, it claims "multiple definition of main()", as QTEST_MAIN is actually another main().
In addition, I got "undefined reference to vtable" on my test class, and don't know why..
I'm using Qt 5.2.1
This is my project file:
#-------------------------------------------------
#
# Project created by QtCreator 2014-06-06T13:42:19
#
#-------------------------------------------------
QT += core gui testlib
CONFIG += testcase
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = GutMiner
TEMPLATE = app
LIBS += -lquazip
SOURCES += main.cpp\
mainwindow.cpp \
dataform.cpp \
datavec.cpp \
distance.cpp \
linereader.cpp \
diseasepackage.cpp \
error.cpp \
newpagedialog.cpp \
resultpage.cpp \
test.cpp
HEADERS += mainwindow.h \
dataform.h \
distance.h \
datavec.h \
linereader.h \
diseasepackage.h \
error.h \
newpagedialog.h \
resultpage.h
FORMS += mainwindow.ui \
dataform.ui \
newpagedialog.ui
and this is my test source file:
#include <QObject>
#include <QTest>
#include "distance.h"
#include "diseasepackage.h"
class TestDistance: public QObject
{
Q_OBJECT
public:
virtual ~TestDistance();
private slots:
void jensen_shannon();
};
TestDistance::~TestDistance() {}
void TestDistance::jensen_shannon()
{
DiseasePackage pkg("CRC.zip");
}
QTEST_MAIN(TestDistance);
One way to make this work properly (the one I use with Qt 4.8) is to have a separate .pro file for the test program.
The main program's .pro file does NOT include the test code.
The test program's .pro file does NOT include main.cpp. The test programs's .pro file does include the test library:
This isn't necessarily the best setup, but it does work nicely, though you end up having to add each source file to both .pro file.
As to your vtable problem, I don't think there's enough info in what you've given to make anything out of that. What class is having the problem? Also, I'm curious why you have an empty destructor on your test class.