Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 运行Qt单元测试_C++_Unit Testing_Qt4 - Fatal编程技术网

C++ 运行Qt单元测试

C++ 运行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 但是,我收到

看看,因为我不想为我要测试的每个类创建一个单独的项目,所以我产生了以下代码:

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