Qt 6, Qt.Future .then freezess app
-
Hey
More or less my code >
auto reply = mNetworkAccessManager->get(initialRequest);//, j.dump().c_str()); auto o = QtFuture::connect(reply, &QNetworkReply::finished) .then(this, [this, reply] { const auto data = icuj::getJsonFromRawString(reply->readAll()); qDebug() << data; qDebug() << reply; return reply; });
Intended to be returned from function as "backend-pre-process-logic" so that I can attach logic after it.
o.then(this, [](QNetworkReply *reply) { qDebug() << "secondary callback?"; return reply; });
However when I try to daisy chain second .then, from o, then the app freezes.
Any ideas? I'm a little lost.I know I can do
.then()
.then()
.then()
But I want to do thens, in different functions/handlers...Edit, ok I take it back, I cant do .then().then().then(), second then freezes app o.o
-
@Dariusz said in Qt 6, Qt.Future .then freezess app:
o.then(this, [](QNetworkReply *reply) { qDebug() << "secondary callback?"; return reply; });
What if you chain them directly?
Maybeo.then()
is the problem?!auto reply = mNetworkAccessManager->get(initialRequest);//, j.dump().c_str()); auto o = QtFuture::connect(reply, &QNetworkReply::finished) .then(this, [this, reply] { const auto data = icuj::getJsonFromRawString(reply->readAll()); qDebug() << data; qDebug() << reply; return reply; }).then(this, [](QNetworkReply *reply) { qDebug() << "secondary callback?"; return reply; });
@Dariusz said in Qt 6, Qt.Future .then freezess app:
.then()
.then()
.then() -
@Pl45m4 For some reason passing this as context caused mutex lock!
I'm now trying to figure out how to perform multiple/nested "then's"....Like >
QFuture<int> networkInit() { QNetworkRequest initialRequest(QUrl("some fancy url")); auto reply = mNetworkAccessManager->get(initialRequest);//, j.dump().c_str()); auto o = QtFuture::connect(reply, &QNetworkReply::finished) .then([reply] { auto data = reply->readAll() return data; }).then([](QByteArray reply) { return 1; }) QObject::connect(reply, &QNetworkReply::finished, reply, QNetworkReply::deleteLater, Qt::QueuedConnection); return o } ///This func breaks :- ) QFuture<QNetworkReply *> requestData(QString adr) { return networkInit().then([this, adr](int status) { if (status == 0) { QNetworkRequest initialRequest(QUrl(adr)); auto reply = mNetworkAccessManager->get(initialRequest); auto futReply= QtFuture::connect(reply, &QNetworkReply::finished) .then([reply] { return reply; }); return futReply; } // raise Exception ??? }); }
/// But if the one above works then I get >
Adding a continuation to a future which already has a continuation. The existing continuation is overwritten. (C:\Users\qt\work\qt\qtbase\src\corelib\thread\qfutureinterface.cpp:940, void __cdecl QFutureInterfaceBase::setContinuation(class std::function<void __cdecl(class QFutureInterfaceBase const &)>,class QFutureInterfaceBasePrivate *))
int main() { auto future = requestData("someFancyDat") future.then([](QNetworkReply *reply) { qDebug() << reply->readAll(); }); }
@Pl45m4 said in Qt 6, Qt.Future .then freezess app:
and then? aaaand then? :D
lolz that's hilarious XDDD
-
Hi,
One issue with your main function is that it does not create any QCoreApplication object hence Qt's internal state is not properly setup.
-
@SGaist I have QApplication - gui one. ah yes the int main() is just a quick hack/example... there full widget app with buttons running :- )
Also I got it to work, I ended up getting nested futures, and the path to fix that is .unwrap()>https://doc.qt.io/qt-6/qfuture.html#unwrap
Seems to work! :DThreading and linking to context still seem to be broken tho o.o