Cath the event of quit from application
-
hi everyone;
i m new in Qt world. i make a simple application as Qt Quick Application. App wizard creat
qtquick2applicationviewer.h, qtquick2applicationviewer.cpp, main.cpp and main qml file .İn main.cpp file app wizard
creat a object as QtQuick2ApplicationViewer for display qml file. i write in qml file this codes for simple rectangle@
import QtQuick 2.0
Rectangle {
id:basitButon
width:100; height:100MouseArea{ id:mouseAlani anchors.fill:parent hoverEnabled: true }
}@
And i want to catch when users want to quit applicaiton. For example when user press the back key ,i want to make a dialog "are you sure to close app " as window.I hope I could tell wanted to do.
-
There are a couple of things you need to do.
First you should perhaps use the appwizard that creates a QtQuick.Controls application for you, simply because it will create a MainWindow as the root of your application. When you have done this you will get an onClosing event that provides exactly what you are looking for.(note you also get this with QtQuick.Window 2.1 as well)
-
can you give me a simple example?
-
I havent tested but from the documentation this should work:
@
Window {
onClosing: {
if (ignoreCloseForSomeReason)
close.accepted = false
}
}
@ -
When I trying these codes,I'm encountering these errors
If your example is using QML 2, (such as qmlscene) and the .qml file you
loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur.To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the
QDeclarativeView class in the Qt Quick 1 module. -
As I mentioned earlier you need to create a completely new project using the wizard in creator that targets Qt Quick Controls. If you use a QQuickView to show your QML code, QML has no control over window creation or destruction as QQuickView itself is a Widget/Window and can only be controlled from C++.
-
ok, I will try controll from c++. Thank you for interest