我有一个包含以下内容的头文件:
#include <QtTest/QtTest>
我正在尝试使用以下行在我的主窗口中生成非阻塞等待:
QTest::qWait(1000 - ui->speedDial->value());
我收到以下错误:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl QTest::qSleep(int)" (__imp_?qSleep@QTest@@YAXH@Z) referenced in function "void __cdecl QTest::qWait(int)" (?qWait@QTest@@YAXH@Z)
任何人都可以帮助我理解我做错了什么,或者提供替代方法吗?这些行独立于其他代码。
最佳答案
它对我来说很好用。检查此示例,它是 Qt Test official documentation example 的修改版本:
tutorial1.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"
关于c++ - Qt 5.2 无法使 qWait 函数工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26874092/