Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to show QWidget and QtQuick.Window
Forum Updated to NodeBB v4.3 + New Features

How to show QWidget and QtQuick.Window

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 359 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Knj.Tkm
    wrote on last edited by
    #1

    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.0

    My 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
        }
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved