0

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?

  • 1
    You cannot move the GUI(QQuickView) to another thread. – eyllanesc Nov 11 '19 at 17:31
  • Thanks @eyllanesc, is there a way to run main.qml processing in another thread? – morteza ali ahmadi Nov 11 '19 at 17:53
  • 1
    No, do not think that using threads is the magic solution to any problem, if you have taken a basic multithreading course you will know that threads can cause bottlenecks. I think you should focus on optimizing your logic and not hoping on the threads. – eyllanesc Nov 11 '19 at 17:56
  • There is at least GUI thread (where your QQuickView runs) in an application and zero or more optional threads in which you should run heavy tasks and then update the main thread accordingly. – folibis Nov 12 '19 at 07:43

0 Answers0