Answer the question
In order to leave comments, you need to log in
Why does PyQt5 QML crash when closing a child window?
In general, the child window opens, everything is fine, but when you click on the cross, Python crashes with this error QPixmap: Must construct a QGuiApplication before a QPixmap
def main():
# Создаем экземпляр приложения
app = QGuiApplication(sys.argv)
# Создаем QML движок
engine = QQmlApplicationEngine()
# загружаем файл qml в движок
path = os.path.abspath("C:/Users/fsociety/Desktop/pyprofiler/test/ui/login.qml")
engine.load(path)
if not engine.rootObjects():
return -1
return app.exec_()
if __name__ == "__main__":
sys.exit(main())
import QtQuick 2.12
import QtQuick.Controls 2.12
ApplicationWindow {
id: loginwindow
visible: true
minimumHeight: 640
maximumHeight: 640
minimumWidth: 1030
maximumWidth: 1030
title: "ProfilerApp"
StackView {
id: stackView
anchors.fill: parent
}
Rectangle {
id: root
width: 430
height: 467
anchors.centerIn: parent
Column {
id: main
width: root.width
height: root.height
spacing: 50
Rectangle {
id: welcome
width: 311
height: 61
anchors.horizontalCenter: main.horizontalCenter
Column {
id: column
width: welcome.width
height: welcome.height
spacing: 7
Rectangle {
width: 213
height: 33
anchors.horizontalCenter: column.horizontalCenter
Text {
text: "Войти в аккаунт"
font.family: "Roboto"
font.pixelSize: 28
color: "#202002"
}
}
Rectangle {
id: second_text
width: 311
height: 21
Text {
text: "Пожалуйста, войдите в аккаунт"
font.family: "Roboto"
font.pixelSize: 18
color: "#202002"
opacity: 0.5
anchors.centerIn: second_text
}
}
}
}
Rectangle {
id: rectangle
width: 430
height: 356
Rectangle {
id: group
width: 340
height: 257
anchors.centerIn: rectangle
Column {
width: width.group
height: height.group
spacing: 15
Rectangle {
id: login
width: 340
height: 56
border.color: "#DDDDDD"
border.width: 1
radius: 4
TextInput {
id: placeholder
maximumLength: 49
anchors.fill: login
anchors.margins: 18
}
}
Rectangle {
id: password
width: 340
height: 56
border.color: "#DDDDDD"
border.width: 1
radius: 4
TextInput {
maximumLength: 49
anchors.fill: password
anchors.margins: 18
}
}
Rectangle {
id: button
width: 340
height: 56
Button {
id: control
text: "Войти в аккаунт"
anchors.fill: button
font.family: "Roboto"
font.pixelSize: 14
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: control.down ? "#FA8072" : "#696969"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 90
implicitHeight: 30
opacity: enabled ? 1 : 0.3
border.color: control.down ? "#FA8072" : "#696969"
border.width: 1
radius: 4
}
}
}
Rectangle {
id: text
y: 15
width: 340
height: 20
Button {
id: auth
text: "Зарегистрироваться"
anchors.fill: text
font.family: "Roboto"
font.pixelSize: 16
contentItem: Text {
text: auth.text
font: auth.font
color: auth.down ? "#ADADAD" : "#696969"
opacity: enabled ? 1 : 0.3
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 90
implicitHeight: 30
opacity: enabled ? 1 : 0.3
}
onClicked: {
stackView.push("registration.qml")
loginwindow.close()
}
}
}
}
}
}
}
}
}
Это дочернее окно registration.qml
import QtQuick 2.12
import QtQuick.Controls 2.12
ApplicationWindow {
id: registration
visible: true
minimumHeight: 640
maximumHeight: 640
minimumWidth: 1030
maximumWidth: 1030
title: "ProfilerApp"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question