osgEarthQt application crash

classic Classic list List threaded Threaded
1 message Options
garbart garbart
Reply | Threaded
Open this post in threaded view
|

osgEarthQt application crash

This post was updated on .
Hi! I'm trying to write a very simple application using osgEarthQt. That's what I got:
Widget::Widget(QWidget *parent) : QWidget(parent)
{
    setWindowTitle("Map");
    int screen_x = QApplication::desktop()->width();
    int screen_y = QApplication::desktop()->height();
    setGeometry((screen_x - 640) / 2, (screen_y - 480) / 2, 640, 480);

    osgViewer::Viewer *viewer = new osgViewer::Viewer();
    EarthManipulator *manipulator = new EarthManipulator();
    viewer->setLightingMode(osg::View::NO_LIGHT);
    viewer->getCamera()->setSmallFeatureCullingPixelSize(-1.0f); //
    viewer->setCameraManipulator(manipulator);

    Map *map = new Map();
    MapNode *mapnode = new MapNode(map);

    Drivers::XYZOptions xyz;
    xyz.url() = "http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png";
    xyz.profile()->namedProfile() = "spherical-mercator";
    ImageLayer* imageLayer = new ImageLayer("OSM", xyz);
    map->addLayer(imageLayer);

    viewer->setSceneData(mapnode);
    MapNodeHelper().configureView(viewer);

    ViewerWidget *viewerWidget = new ViewerWidget(viewer);

    QGridLayout *layout = new QGridLayout();
    layout->addWidget(viewerWidget);
    setLayout(layout);
}


However, the app is crashing and I getting an error:
Cannot make QOpenGLContext current in a different thread

Okey. I tried to remove all osgEarthQt objects:
Widget::Widget(QWidget *parent) : QWidget(parent)
{
    osgViewer::Viewer *viewer = new osgViewer::Viewer();
    EarthManipulator *manipulator = new EarthManipulator();
    viewer->setLightingMode(osg::View::NO_LIGHT);
    viewer->getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
    viewer->setCameraManipulator(manipulator);

    Map *map = new Map();
    MapNode *mapnode = new MapNode(map);

    Drivers::XYZOptions xyz;
    xyz.url() = "http://[abc].tile.openstreetmap.org/{z}/{x}/{y}.png";
    xyz.profile()->namedProfile() = "spherical-mercator";
    ImageLayer* imageLayer = new ImageLayer("OSM", xyz);
    map->addLayer(imageLayer);

    viewer->setSceneData(mapnode);
    MapNodeHelper().configureView(viewer);

    viewer->run();
}


And it worked, the map appeared. However, I would like to use the map inside my Qt application. What is the reason for this error? How can it be corrected?
I'm using osgEarth 2.9.0 and Qt 5.11