我有一个头文件,其中包括:
#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 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/