How to show QWidget and QtQuick.Window
Unsolved
QML and Qt Quick
-
Hi.
I need to show QWidget and QtQuick.Window.
However, when I try to do so, it force quits.
When I ran it in debug, I found that SIGSEGV was occurring, but I don't know how to avoid it.
SIGSEGV is occurring at windowForWidget in qapplication_p.h.
How can I do this correctly?My environment:
Qt: 1.15.2 (QMake)
Compiler: MinGW7.3.0My Code:
//main.cpp #include <QGuiApplication> #include <QApplication> #include <QQmlApplicationEngine> #include "Form.h" int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif qmlRegisterType<Form>("Form", 1, 0, "Form"); QApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
//Form.h #ifndef FORM_H #define FORM_H #include <QObject> #include <QWidget> namespace Ui { class Form; } class Form : public QWidget { Q_OBJECT public: Form(); private: Ui::Form *ui; }; #endif // FORM_H //Form.cpp #include "Form.h" #include "ui_Form.h" Form::Form() : QWidget(), ui(new Ui::Form) { ui->setupUi(this); }
//main.qml import QtQuick 2.15 import QtQuick.Window 2.15 import Form 1.0 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") Form { id: myForm } }
-
Hi,
That's because widgets are not meant to be embedded like that.
You can check KDAB's Declarative Widget project to mix widgets and QtQuick.