1

I'm writing test automation in QT. I'am using QTest::qWaitFor to wait until the event loop switches to another tab in UI.

QTest::qWaitFor([tabs, &currentIdx]() {
    currentIdx = tabs->currentIndex();
    return currentIdx == 1;
}, 5000);

Each time I'am using such construction following warning appears:

ignoring return value of function declared with 'warn_unused_result' attribute

I spent hours dealing with it but no result. I think the problem is the way functions consume returned values from lambda expressions. Is there any workaround?

Piotr Zych
  • 483
  • 4
  • 19
  • 1
    You should check return of `qWaitFor` to know if timeout happens. – Jarod42 Jun 25 '21 at 10:12
  • @Jarod42 Thank you very much. With no reason I was sure the warning applies to lambda expression. Handling result of qWaitFor or casting it to void works well. – Piotr Zych Jun 25 '21 at 10:20

1 Answers1

2

Issue is not with lambda, but your usage:

You should use/check return value of qWaitFor (to know if timeout happens):

if (QTest::qWaitFor([tabs, &currentIdx]() {
        currentIdx = tabs->currentIndex();
        return currentIdx == 1;
    }, 5000)) {
    // OK.
    // ...
} else {
    // timeout.
    // ...
}
Jarod42
  • 203,559
  • 14
  • 181
  • 302