int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
requester req;
replier rep;
req.moveToThread(&requesterThread);
rep.moveToThread(&replierThread);
req.connect(&requesterThread, SIGNAL(started()), SLOT(runReq())); //where runReq() is the main method of my requester class
rep.connect(&replierThread, SIGNAL(started()), SLOT(runRep()));
req.connect(&requesterThread,SIGNAL(finished()),SLOT(deleteLater()));
rep.connect(&replierThread,SIGNAL(finished()),SLOT(deleteLater()));
&requesterThread.connect(&requesterThread,SIGNAL(finished()),SLOT(deleteLater()));
&replierThread.connect(&replierThread,SIGNAL(finished()),SLOT(deleteLater()));
//Setting context properties
viewer.rootContext()->setContextProperty("requester",&req );
viewer.rootContext()->setContextProperty("replier", &rep);
viewer.rootContext()->setContextProperty("requesterTHREAD",&requesterThread );
viewer.rootContext()->setContextProperty("replierTHREAD", &replierThread);
viewer.setMainQmlFile(QStringLiteral("qml/ProjectUsecase1/main.qml"));
viewer.showExpanded();
return app.exec();
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
requester req;
replier rep;
QThread requesterThread;
QThread replierThread;
req.moveToThread(&requesterThread);
rep.moveToThread(&replierThread);
req.connect(&requesterThread, SIGNAL(started()), SLOT(runReq())); //where runReq() is the main method of my requester class
rep.connect(&replierThread, SIGNAL(started()), SLOT(runRep()));
req.connect(&requesterThread,SIGNAL(finished()),SLOT(deleteLater()));
rep.connect(&replierThread,SIGNAL(finished()),SLOT(deleteLater()));
&requesterThread.connect(&requesterThread,SIGNAL(finished()),SLOT(deleteLater()));
&replierThread.connect(&replierThread,SIGNAL(finished()),SLOT(deleteLater()));
//Setting context properties
viewer.rootContext()->setContextProperty("requester",&req );
viewer.rootContext()->setContextProperty("replier", &rep);
viewer.rootContext()->setContextProperty("requesterTHREAD",&requesterThread );
viewer.rootContext()->setContextProperty("replierTHREAD", &replierThread);
viewer.setMainQmlFile(QStringLiteral("qml/ProjectUsecase1/main.qml"));
viewer.showExpanded();
return app.exec();
To copy to clipboard, switch view to plain text mode
Bookmarks