Qt 5.2无法获得qWait功能

时间:2014-11-11 20:38:45

标签: c++ qt5.2

我有一个包含以下内容的头文件:

#include <QtTest/QtTest>

我正在尝试使用以下行在我的主窗口中生成非阻塞等待:

QTest::qWait(1000 - ui->speedDial->value());

我收到以下错误:

  

mainwindow.obj:-1:错误:LNK2019:未解析的外部符号&#34; __ declspec(dllimport)void __cdecl QTest :: qSleep(int)&#34; (__imp_?qSleep @ QTest @@ YAXH @ Z)在函数&#34; void __cdecl QTest :: qWait(int)&#34;中引用(?qWait @ @@ QTEST @ YAXH Z)

任何人都可以帮助我理解我做错了什么,或提供替代方法吗?这些行独立于其他代码。

1 个答案:

答案 0 :(得分:1)

对我来说很好。请查看此示例,该示例是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"