Prevent Messagedialog from closing application
-
Hi,
I deleted (sorry for deleting, guess thats not the right way) to early my old question, but anyway here again:Lets say I have one ApplicationWindow:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 import QtQuick.Controls.impl 2.3 import QtQuick.Dialogs 1.1 import QtCharts 2.3 ApplicationWindow { id: applicationWindow1 width: 640 height: 480 visible: true title: qsTr("Hello World") Loader{ id:loader } Button { id: button x: 270 y: 220 text: qsTr("Button") onClicked: { applicationWindow1.visible = false; loader.source = "test123.qml"; } } }
And the otherone which is loaded:
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 import QtQuick.Controls.impl 2.3 import QtQuick.Dialogs 1.1 import QtCharts 2.3 ApplicationWindow { id: applicationWindow2 width: 640 height: 480 visible: true title: qsTr("New") MessageDialog{ id: analysisDone visible: true standardButtons: StandardButton.Ok } }
What is the right way to prevent, that the closing of the Messagedialog closes the whole application?
-
Not sure what are you trying to achieve, but I do not think that having two
ApplicationWindow
instances in one application is an a good idea. If you want to show dialog by pressing button, you can have it defined in your first qml, just set it to unvisible:Button { onClicked: dlg.open() } MessageDialog { id: dlg visible: false }
If you want to save a bit of memory, you can go in dynamic way, using
Component
, but make sure if you destroy your objects properly. -
@IntruderExcluder said in Prevent Messagedialog from closing application:
Not sure what are you trying to achieve, but I do not think that having two
ApplicationWindow
instances in one application is an a good idea.There's nothing special about
ApplicationWindow
, having 2 of them is not a problem.
It's just a convenience class on top of Window with builtin support for header, footer and overlays. -
it seems that it is important which file is used in the engine
QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/login.qml")));
As long as i keep everything in this qml the behaviour is "normal". If I change to another ApplicationWindow with a loader I get the strange thinks.
Maybe I have to change to a layout with only one ApplicationWindow