fix: fix crash on removing title bar
This commit is contained in:
parent
0dfd39afe2
commit
c94b801e37
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QWindow>
|
||||
#include <QDebug>
|
||||
|
||||
#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<StatusWindow>("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<QWindow*>(m_engine.rootObjects().at(0));
|
||||
if (rootWindow) {
|
||||
removeTitleBar(rootWindow->winId());
|
||||
} else {
|
||||
qDebug() << "Window doesn't exist";
|
||||
}
|
||||
}
|
||||
|
||||
void SandboxApp::restartEngine()
|
||||
|
|
|
@ -13,8 +13,6 @@ public:
|
|||
|
||||
void startEngine();
|
||||
|
||||
void removeTitleBar(WId wid);
|
||||
|
||||
public slots:
|
||||
void restartEngine();
|
||||
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef STATUSWINDOW_H
|
||||
#define STATUSWINDOW_H
|
||||
|
||||
#include <QQuickWindow>
|
||||
|
||||
class StatusWindow: public QQuickWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit StatusWindow(QWindow *parent = nullptr)
|
||||
: QQuickWindow(parent)
|
||||
{
|
||||
removeTitleBar(winId());
|
||||
}
|
||||
|
||||
private:
|
||||
void removeTitleBar(WId wid);
|
||||
};
|
||||
|
||||
#endif // STATUSWINDOW_H
|
|
@ -1,4 +1,4 @@
|
|||
#include "sandboxapp.h"
|
||||
#include "statuswindow.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
|||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
|
||||
void SandboxApp::removeTitleBar(WId wid)
|
||||
void StatusWindow::removeTitleBar(WId wid)
|
||||
{
|
||||
NSView *nsView = reinterpret_cast<NSView*>(wid);
|
||||
NSWindow *window = [nsView window];
|
Loading…
Reference in New Issue