0

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

#include <QtTest/QtTest>

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

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

我收到以下错误:

mainwindow.obj:-1: 错误: LNK2019: 函数“void __cdecl QTest:: qWait(int)" (?qWait@QTest@@YAXH@Z)

谁能帮助我了解我做错了什么,或提供替代方法?这些行独立于其他代码。

4

1 回答 1

1

这对我来说可以。检查此示例,它是Qt 测试官方文档示例的修改版本:

教程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)

测试字符串.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"
于 2014-11-11T21:39:44.363 回答