osg嵌入Qt窗口完整代码的一个示例:
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
#include <QTimer>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
class OSGWidget : public QWidget
{
public:
OSGWidget(QWidget* parent = nullptr)
: QWidget(parent, Qt::Widget)
, _viewer(new osgViewer::Viewer())
{
// Create a widget to contain the osg viewer
QWidget* widget = QWidget::createWindowContainer(_viewer->setUpViewerAsEmbeddedInWindow(0, 0, width(), height()));
// Set up the camera manipulator
_viewer->setCameraManipulator(new osgGA::TrackballManipulator);
// Load a model to display
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile("cow.osg");
if (scene)
{
_viewer->setSceneData(scene);
}