TransWikia.com

QGIS - How to render QgsMapCanvas on QApplication's main window

Geographic Information Systems Asked by tilt_y on August 18, 2021

I am working with C++, QT 5.11.3, Visual Studio 2015 and QGIS 3.7

I’m trying to develop QT c++ application that uses the qgis api. I want to display simple raster and vector map in my qt application.
I create QgsVectorLayer and QgsRasterLayer that added to the QgsProject instance and then QgsMapCanvas object. That is no problem so far.

But when i turn the visible property of QgsMapCanvas object, the application crash. The error message and the crash window is above.

QCoreApplication::sendEvent: “Cannot send events to objects owned by a different thread. Current thread … Reciever (of type ‘QGSMapCanvas’) …

enter image description here

I try to this process at different qt thread or main thread no matter what, does not help.
What can i do wrong?

One Answer

Use the following code in the constructor of your main window:

this->setCentralWidget(canvas)

where canvas is the name of your map canvas. This will replace the central area of your main window with the canvas.

Answered by Aurus Huang on August 18, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP