Czy watek std::thread
może uruchomić funkcję w kontekście głównego wątku aplikacji Qt i zaczekać na zakończenie tej funkcji ?
Coś jak Qt::BlockingQueuedConnection
? Tyko nie mogę tego uzyć jak oba watki nie sa z Qt
main.cpp
int main(int argc, char *argv[])
{
using namespace httplib;
QApplication a(argc, argv);
Widget w;
w.show();
Server svr;
svr.Get("/img", [&](const httplib::Request &, httplib::Response &res) {
QByteArray data;
if (w.getPng(data))
{
res.set_content(data.data(), data.length(), "image/png");
}
else
{
res.status = 502;
}
});
auto httpThread = std::thread([&]() { svr.listen("0.0.0.0", 8181); });
system("start http://localhost:8181/img");
return a.exec();
}
getPng musi byc uruchomione w głównym wątku
bool Widget::getPng(QByteArray &data)
{
auto pixmap = grab();
QImage image = pixmap.toImage();
QBuffer inBuffer(&data);
inBuffer.open(QIODevice::WriteOnly);
image.save(&inBuffer, "PNG");
return true;
}
jak to pokonać ?