From c94b801e372919385dba457ee31493cd2e816960 Mon Sep 17 00:00:00 2001 From: "B.Melnik" Date: Thu, 20 May 2021 09:25:52 +0300 Subject: [PATCH] fix: fix crash on removing title bar --- sandbox/main.qml | 4 +++- sandbox/sandbox.pro | 5 +++-- sandbox/sandboxapp.cpp | 11 ++++------ sandbox/sandboxapp.h | 2 -- sandbox/statuswindow.h | 21 +++++++++++++++++++ ...{sandboxapp_mac.mm => statuswindow_mac.mm} | 4 ++-- 6 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 sandbox/statuswindow.h rename sandbox/{sandboxapp_mac.mm => statuswindow_mac.mm} (85%) diff --git a/sandbox/main.qml b/sandbox/main.qml index c1f8dbb0..6ba995db 100644 --- a/sandbox/main.qml +++ b/sandbox/main.qml @@ -2,10 +2,12 @@ import QtQuick 2.14 import QtQuick.Window 2.14 import QtQuick.Controls 2.14 +import Sandbox 0.1 + import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 -Window { +StatusWindow { id: rootWindow width: 1024 height: 840 diff --git a/sandbox/sandbox.pro b/sandbox/sandbox.pro index e3fe24c5..039aa49f 100644 --- a/sandbox/sandbox.pro +++ b/sandbox/sandbox.pro @@ -12,7 +12,7 @@ SOURCES += \ sandboxapp.cpp OBJECTIVE_SOURCES += \ - sandboxapp_mac.mm + statuswindow_mac.mm RESOURCES += qml.qrc @@ -28,7 +28,8 @@ OTHER_FILES += $$files($$PWD/../src/*, true) HEADERS += \ handler.h \ - sandboxapp.h + sandboxapp.h \ + statuswindow.h DISTFILES += \ ../src/StatusQ/Controls/StatusBaseButton.qml \ diff --git a/sandbox/sandboxapp.cpp b/sandbox/sandboxapp.cpp index cc4eeeed..2c7d2834 100644 --- a/sandbox/sandboxapp.cpp +++ b/sandbox/sandboxapp.cpp @@ -4,6 +4,8 @@ #include #include +#include "statuswindow.h" + SandboxApp::SandboxApp(int &argc, char **argv) : QGuiApplication(argc, argv), m_handler(new Handler(this)) @@ -13,6 +15,8 @@ SandboxApp::SandboxApp(int &argc, char **argv) void SandboxApp::startEngine() { + qmlRegisterType("Sandbox", 0, 1, "StatusWindow"); + const QUrl url(applicationDirPath() + "/../main.qml"); m_engine.rootContext()->setContextProperty("app", m_handler); @@ -25,13 +29,6 @@ void SandboxApp::startEngine() QCoreApplication::exit(-1); }, Qt::QueuedConnection); m_engine.load(url); - - QWindow *rootWindow = qobject_cast(m_engine.rootObjects().at(0)); - if (rootWindow) { - removeTitleBar(rootWindow->winId()); - } else { - qDebug() << "Window doesn't exist"; - } } void SandboxApp::restartEngine() diff --git a/sandbox/sandboxapp.h b/sandbox/sandboxapp.h index 834d7045..8589baab 100644 --- a/sandbox/sandboxapp.h +++ b/sandbox/sandboxapp.h @@ -13,8 +13,6 @@ public: void startEngine(); - void removeTitleBar(WId wid); - public slots: void restartEngine(); diff --git a/sandbox/statuswindow.h b/sandbox/statuswindow.h new file mode 100644 index 00000000..4bbcf9c6 --- /dev/null +++ b/sandbox/statuswindow.h @@ -0,0 +1,21 @@ +#ifndef STATUSWINDOW_H +#define STATUSWINDOW_H + +#include + +class StatusWindow: public QQuickWindow +{ + Q_OBJECT + +public: + explicit StatusWindow(QWindow *parent = nullptr) + : QQuickWindow(parent) + { + removeTitleBar(winId()); + } + +private: + void removeTitleBar(WId wid); +}; + +#endif // STATUSWINDOW_H diff --git a/sandbox/sandboxapp_mac.mm b/sandbox/statuswindow_mac.mm similarity index 85% rename from sandbox/sandboxapp_mac.mm rename to sandbox/statuswindow_mac.mm index f4b5c608..25c6a665 100644 --- a/sandbox/sandboxapp_mac.mm +++ b/sandbox/statuswindow_mac.mm @@ -1,4 +1,4 @@ -#include "sandboxapp.h" +#include "statuswindow.h" #include @@ -7,7 +7,7 @@ #include #include -void SandboxApp::removeTitleBar(WId wid) +void StatusWindow::removeTitleBar(WId wid) { NSView *nsView = reinterpret_cast(wid); NSWindow *window = [nsView window];