我有一个包含以下内容的头文件:
#include <QtTest/QtTest>
我正在尝试使用以下行在我的主窗口中生成非阻塞等待:
QTest::qWait(1000 - ui->speedDial->value());
我收到以下错误:
mainwindow.obj:-1:错误:LNK2019:未解析的外部符号"__declspec(dllimport)void __cdecl QTest::qSleep(int)"(__imp_?qSleep@QTest@@YAXH@Z)在函数"void __cdecl QTest::qWait(int)"中引用(?qWait@QTest@@YAXH@Z)
有人能帮助我理解我做错了什么,或者提供一种替代方法吗?这些行独立于其他代码。
它对我来说很好。查看这个例子,它是Qt Test官方文档的修改版本示例:
教程1.pro:
SOURCES = testqstring.cpp
CONFIG += qtestlib
# install
target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
sources.files = $$SOURCES *.pro
sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
INSTALLS += target sources
symbian {
TARGET.UID3 = 0xA000C60B
include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri)
}
maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri)
symbian: warning(This example might not fully work on Symbian platform)
maemo5: warning(This example might not fully work on Maemo platform)
simulator: warning(This example might not fully work on Simulator platform)
testqstring.cpp:
#include <QtTest/QtTest>
#include <QDebug>
class TestQString: public QObject
{
Q_OBJECT
private slots:
void toUpper();
};
void TestQString::toUpper()
{
QString str = "Hello";
QTest::qWait(2000);
QCOMPARE(str.toUpper(), QString("HELLO"));
}
QTEST_MAIN(TestQString)
#include "testqstring.moc"