Problem With QTest::qSleep()



  • Inside a loop that is filling a listWidget with potentially millions of items I want to check if a cancel button has been pressed:

    @void TextBox::on_fillButton_clicked() {
    QStringList lines;
    for (int i=0; i < 100000; i++) {
    if (i % 1000 == 0) {
    QTest::qWait(0);
    if (actionCancelled) {
    actionCancelled = false;
    return;
    }
    }
    std::ostringstream ostr;
    ostr << "line " << i;
    lines << ostr.str().c_str();
    }

    ui->listWidget->addItems(lines);
    

    }@

    My hope was that the call to QTest::qWait() would allow the click on the Cancel button to be detected and its slot method called:

    @void TextBox::on_cancelButton_clicked() {
    actionCancelled = true;
    }@

    But it won't run because QTest::qWait() is implemented using QTest::qSleep(), and it seems to be an undefined reference:

    @undefined reference to `QTest::qSleep(int)'@

    Looking in qtestcase.h I see that QTest::qSleep() is defined like this:

    @Q_TESTLIB_EXPORT void qSleep(int ms);@

    Poking around the web I see that QTest::qSleep() is implemented on Windows using its Sleep function, so maybe the association between QTest::qSleep() and the Windows Sleep function is failing to be made, somehow.

    So I guess the questions are:

    If it's pilot error, what am I doing wrong?

    If it's a problem with my installation, how do I fix it?

    If I'm approaching this the wrong way, what approach should I take?

    --Percy



  • "QCoreApplication::processEvents()":http://qt-project.org/doc/qt-4.8/qcoreapplication.html#processEvents is what you are looking for.

    If you want to use functionality of the QtTest library you will have to add <code>QT += testlib</code> to your <code>.pro</code> file.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.