2012-08-22 164 views
0

基本上我遵循基本示例here。我的.pro文件包含QT += core network qtestlib。 [解決] TESTLIB,而不是錯字qtestlibQt:與QVERIFY(Qt單元測試)的鏈接器錯誤

當我包括QVERIFY,它得到下面的連接錯誤:

testwaypointlist.obj:-1: error: LNK2019: unresolved external symbol "bool __cdecl 
QTest::qVerify(bool,char const *,char const *,char const *,int)" 
([email protected]@@[email protected]) referenced in function "private: void __thiscall 
TestWaypointList::fillWaypoints(void)" ([email protected]@@AAEXXZ) 

我錯過了什麼要鏈接的文件?沒有QVERIFY鏈接器錯誤消失。

頭文件

#include <QObject> 
#include <QtTest/QtTest> 
#include "waypointlist.h" 

// 
// Testing the waypoint list 
// 
class TestWaypointList : public QObject 
{ 
    Q_OBJECT 

private: 
    WaypointList _waypointList; 
public: 
    explicit TestWaypointList(QObject *parent = 0); 
private slots: 
    void fillWaypoints(); 
}; 

CPP:

// 
// Fill the waypoint list 
// 
void TestWaypointList::fillWaypoints() 
{ 
    _waypointList = WaypointList(); 
    ..... 

    for (int i=0; i < TESTWPLISTCOUNT; i++) { 
     ..... 
     TestWaypointList::_waypointList.updateOrAppend(id, timeframe); 
    } 
    QVERIFY(TestWaypointList::_waypointList.count() == 1); // causing the linker error 
} 
+1

它應該是你的.pro文件中的QT + = testlib,而不是QT + = qtestlib。 –

+0

就是這樣,我誤解了這個例子:http://doc.qt.nokia.com/4.7-snapshot/qtestlib-tutorial1-tutorial1-pro.html如果你把它寫成答案,我會很樂意接受它。我所有的錯:-( –

回答

2

在你的.pro文件,你需要改變QT += qtestlibQT += testlib(注意,沒有 「Q」 的)。

值得注意的是,您曾經可以這樣做:CONFIG += qtestlib,但根據this page的評論,這不再是連接到測試庫的推薦方式。