QOpenGLWidget embedded in qml
-
Hello,
I have a QOpenGLWidget class, how can it be embedded in qml? I use qmlRegisterType(), but I got a segmentation fault. Below it's some code.class MyGLWidget: public QOpenGLWidget { Q_OBJECT public: explicit MyGLWidget(QWidget* parent = NULL); virtual ~MyGLWidget(); }main.cpp
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); qmlRegisterType<MyGLWidget>("MyClass", 1, 0, "MyClass"); QQuickView view(QUrl("qrc:/main.qml")); view.show(); return app.exec(); }main.qml:
import QtQuick 2.8 import MyClass 1.0 Item { width: 800 height: 600 MyClass { id: glWindow } }QT version 5.14.2
-
Hello,
I have a QOpenGLWidget class, how can it be embedded in qml? I use qmlRegisterType(), but I got a segmentation fault. Below it's some code.class MyGLWidget: public QOpenGLWidget { Q_OBJECT public: explicit MyGLWidget(QWidget* parent = NULL); virtual ~MyGLWidget(); }main.cpp
int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); qmlRegisterType<MyGLWidget>("MyClass", 1, 0, "MyClass"); QQuickView view(QUrl("qrc:/main.qml")); view.show(); return app.exec(); }main.qml:
import QtQuick 2.8 import MyClass 1.0 Item { width: 800 height: 600 MyClass { id: glWindow } }QT version 5.14.2
@Mavis I guess you are trying to use opengl raw code in qml. If my guess is correct, you can create a
class CustomOpenGLItem : public QQuickItem, protected QOpenGLFunctions
and put your raw code inside and you can add this class in qml code.
I do not think you are able to add QOpenGLWidget to qml directly.qmlRegisterType<CustomOpenGLItem>("CustomOpenGLItem", 1, 0, "CustomOpenGLItem"); ============= import QtQuick 2.15 import CustomOpenGLItem 1.0 ApplicationWindow { visible: true width: 400 height: 300 title: "OpenGL in QML Example" CustomOpenGLItem { anchors.fill: parent } } -
@Mavis I guess you are trying to use opengl raw code in qml. If my guess is correct, you can create a
class CustomOpenGLItem : public QQuickItem, protected QOpenGLFunctions
and put your raw code inside and you can add this class in qml code.
I do not think you are able to add QOpenGLWidget to qml directly.qmlRegisterType<CustomOpenGLItem>("CustomOpenGLItem", 1, 0, "CustomOpenGLItem"); ============= import QtQuick 2.15 import CustomOpenGLItem 1.0 ApplicationWindow { visible: true width: 400 height: 300 title: "OpenGL in QML Example" CustomOpenGLItem { anchors.fill: parent } }