Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QFuture then continuation never finishes

QFuture then continuation never finishes

Scheduled Pinned Locked Moved Unsolved Qt 6
1 Posts 1 Posters 206 Views 2 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
    pusheax
    wrote on last edited by pusheax
    #1

    Hello, I have a question about QFuture and their continuation then API. Consider the following example code:

    auto future = getAccountToken("test@mailprovider.com", "password")
            .then([this](QFuture<QString> f) {
                auto const token = f.result();
                return getGameAccounts(token);
            })
            .then([this](QFuture<QList<GameAccount>> f) {
                auto const gameAccounts = f.result();
                // --> LINE NEVER REACHED (WAITS FOREVER ON f.result() CALL)
            });
    

    And:

    QFuture<QString> getAccountToken(/*...*/)
    {
        QPromise<QString> promise;
        auto future = promise.future();
    
        promise.start();
    
        QNetworkRequest request(QUrl("https://example.org"));
        // ...
        auto reply = networkMngr->post(request, doc.toJson());
        connect(reply, &QNetworkReply::finished, [reply, p = std::move(promise)]() mutable {
            p.addResult("<TOKEN FROM REPLY>");
            p.finish();
    
            reply->deleteLater();
        });
    
        return future;
    }
    

    The function getGameAccounts has the same boilerplate code as getAccountToken, except that it performs a GET request instead.
    Does anyone know why I never reach the line after auto const gameAccounts = f.result(); ? A single .then continuation works fine.
    FYI: I don't reach the connect lambda for the reply in getGameAccounts either, which explains why I never have any result. But I can't seem to figure out why that happens.

    Thank you in advance.

    1 Reply Last reply
    0

    • Login

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