C++ 运行Qt单元测试
看看,因为我不想为我要测试的每个类创建一个单独的项目,所以我产生了以下代码: testqstring.hC++ 运行Qt单元测试,c++,unit-testing,qt4,C++,Unit Testing,Qt4,看看,因为我不想为我要测试的每个类创建一个单独的项目,所以我产生了以下代码: testqstring.h #ifndef TESTQSTRING_H #define TESTQSTRING_H #include <QtTest/QTest> class TestQString : public QObject { Q_OBJECT private slots: void toUpper(); }; #endif // TESTQSTRING_H 但是,我收到
#ifndef TESTQSTRING_H
#define TESTQSTRING_H
#include <QtTest/QTest>
class TestQString : public QObject
{
Q_OBJECT
private slots:
void toUpper();
};
#endif // TESTQSTRING_H
但是,我收到以下链接器错误:
...
g++ -headerpad_max_install_names -arch i386 -o tester main.o testqstring.o moc_testqstring.o -F/Library/Frameworks -L/Library/Frameworks -framework QtCore
Undefined symbols:
"QTest::qExec(QObject*, int, char**)", referenced from:
_main in main.o
"QTest::compare_helper(bool, char const*, char*, char*, char const*, char const*, char const*, int)", referenced from:
bool QTest::qCompare<QString>(QString const&, QString const&, char const*, char const*, char const*, int)in testqstring.o
... and more like that ...
。。。
g++-headerpad_max_install_name-arch i386-o tester main.o testqstring.o moc_testqstring.o-F/Library/Frameworks-L/Library/Frameworks-framework QtCore
未定义的符号:
“QTest::qExec(QObject*,int,char**)”,引用自:
_主音中的主音
“QTest::compare_helper(bool,char const*,char*,char*,char const*,char const*,char const*,int)”,引用自:
boolqtest::testqstring.o中的qCompare(QString常量&,QString常量&,char常量*,char常量*,char常量*,int)
... 更像这样。。。
我做错了什么?添加:
CONFIG += qtestlib
将qmake链接到qtest库中的.pro文件。您不需要链接到qtest吗?@Noah这是什么意思?还是现在的“QT+=testlib”
...
g++ -headerpad_max_install_names -arch i386 -o tester main.o testqstring.o moc_testqstring.o -F/Library/Frameworks -L/Library/Frameworks -framework QtCore
Undefined symbols:
"QTest::qExec(QObject*, int, char**)", referenced from:
_main in main.o
"QTest::compare_helper(bool, char const*, char*, char*, char const*, char const*, char const*, int)", referenced from:
bool QTest::qCompare<QString>(QString const&, QString const&, char const*, char const*, char const*, int)in testqstring.o
... and more like that ...
CONFIG += qtestlib