4

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?

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.