morteza ali ahmadi
morteza ali ahmadi

Reputation: 455

Running QQuickView of the MainWindow in a seprate thread in Qt

I have an application which has some modules in different tabs in Ui. In one of these tabs, I have a verticalLayout (map_verticalLayout) and I want to add a QQuickView (mapView) in this layout. In the constructor of the mainwindow.cpp I used the following code:

...
QQuickView* mapView = new QQuickView();
QWidget *mapWidget = QWidget::createWindowContainer(mapView, this);
ui->map_verticalLayout->addWidget(mapWidget);
mapView->engine()->rootContext()->setContextProperty("loc", NodesMap::getInstance());
mapView->setSource(QUrl(QStringLiteral("qrc:/map/main.qml")));
mapView->setResizeMode(QQuickView::SizeRootObjectToView);
...

The above code works well when there is no heavy processing in the main.qml. But in some cases there is a huge delay in main.qml (because of the high number of points on the map) which causes mainwindow to freeze. Now I want to run my QQuickView (mapView) or main.qml processing in another thread. I saw the similar questions in enter link description here and enter link description here but these questions are almost different from mine and their answers does not solve my question. What is the solution?

Upvotes: 0

Views: 249

Answers (0)

Related Questions