0

I've got a header file with the following include:

#include <QtTest/QtTest>

I am trying to use the following line to generate a non-blocking wait in my main window:

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

I receive the following error:

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)

Can anyone help me understand what I am doing wrong, or provide an alternative method? These lines are independent of other code.

  • 1
    Did you add `QT += testlib` in your `*.pro` file? If not, add it, run `qmake` again and rebuild. – Iuliu Nov 11 '14 at 20:54
  • I am not as familiar with using make files as I should be; that being said, upon following your instructions I now have several warnings. The program still doesn't compile. What have I done wrong? – Kenneth McKanders Nov 11 '14 at 21:08
  • Can you please see my answer? I posted an example in which `qWait` works ok. You can take it as example and compare to your code in order to see what it is different. Can you also post some of the code? It would help me figure it out as this simple `Qt` example works without any special modification. – Iuliu Nov 11 '14 at 21:41

1 Answers1

1

It works fine for me. Check this example which is a modified version of the 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"
Iuliu
  • 4,001
  • 19
  • 31