Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problem With QTest::qSleep()
Forum Updated to NodeBB v4.3 + New Features

Problem With QTest::qSleep()

Scheduled Pinned Locked Moved Qt Creator and other tools
2 Posts 2 Posters 8.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Percipient
    wrote on 20 May 2012, 21:11 last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 21 May 2012, 06:21 last edited by
      #2

      "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.

      1 Reply Last reply
      0

      1/2

      20 May 2012, 21:11

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved