How to resolve warning "ignoring return value of function declared with 'warn_unused_result' attribute"

1.4k Views Asked by At

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?

1

There are 1 best solutions below

0
Jarod42 On BEST ANSWER

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.
    // ...
}