Quit app after Toast message dissapears - qml

I've found fantastic topic on creation of Qt/QML implementation of Android Toast. I am trying to upgrade it after Toast disappears some signal is emmited - I want to quit simple Qt/QML app. Here is ToastManager:
import QtQuick 2.7
Column
{
id: root
z: Infinity
spacing: 5
anchors.centerIn: parent
signal signalQuitApp;
property var toastComponent
function show(text,
duration)
{
var toast=toastComponent.createObject(root);
toast.selfDestroying=true;
toast.show(text,
duration);
signalQuitApp();
} // show
Component.onCompleted:
{
toastComponent=Qt.createComponent("Toast.qml");
} // Component.onCompleted
} // Column
The result is, if I click some button inside QML application, it quits before Toast animation is over. How do I emit signal AFTER Toast dissapears?

Assuming you are referring to the answer by #ayberk-Özgür you will need to modify Toast.qml to emit the signal when it is done.
id: root
signal toastFinished()
// ...
onRunningChanged:{
if (!running) {
root.toastFinished();
if (selftDestroying)
root.destroy();
}
}
Before you show the toast you connect to that signal
toast.toastFinished.connect(Qt.quit);
toast.show(text, duration);

Related

How do I go directly from FullScreen to Maximized in a QML Window?

Below is a small QML application. What I intended was for the application to start full screen, and on the Escape key, change it to maximized:
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
id: topLevelWindow
width: 640
height: 480
visible: true
title: qsTr("Hello World")
visibility: Window.FullScreen
Rectangle {
id: rect
anchors.fill: parent
color: "lightBlue"
focus: true
Keys.onPressed: {
if (event.key === Qt.Key_Escape) {
rect.color = "lightGreen"
topLevelWindow.visibility = Window.Maximized
}
}
}
}
What actually happens, though, is that it starts full screen as intended, but pressing Escape makes it windowed but not maximized. Pressing Escape a second time actually maximizes it.
Is there a way to do this without making the user hit Escape twice?
It looks like this is indeed a bug. Seems like it's been lingering for a while, but (some) newer versions may have fixed it?
In the meantime, it's relatively easy to add a hacky workaround:
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
id: topLevelWindow
width: 640
height: 480
visible: true
title: qsTr("Hello World")
visibility: Window.FullScreen
Rectangle {
id: rect
anchors.fill: parent
color: "lightBlue"
focus: true
Keys.onPressed: {
if (event.key === Qt.Key_Escape) {
rect.color = "lightGreen"
topLevelWindow.visibility = Window.Windowed
windowHackTimer.start()
}
}
}
Timer {
id: windowHackTimer
interval: 0
repeat: false
onTriggered: {
topLevelWindow.visibility = Window.Maximized
}
}
}
On the button press it becomes windowed, and then after it returns to the event loop (with a 0ms timer), it sets it to maximized. Just setting topLevelWindow.visibility multiple times in Keys.onPressed doesn't get the job done.
I think you should (1) make sure that the Escape key is accepted by your event handler (so that it is not passed down) and (2) schedule the outcome with Qt.callLater.
Keys.onPressed: {
if (event.key === Qt.Key_Escape) {
event.accepted = true;
Qt.callLater( greenRectAndMaximize );
}
}
function greenRectAndMaximize() {
rect.color = "lightGreen";
topLevelWindow.visibility = Window.Maximized;
}
The event.accept() is important to ensure that no other UI will handle the same event. That could be the cause of your problem. The Qt.callLater is important because it ensures that your action is added to the end of the windows messaging queue so that the UI/UX for the Escape key (and any other UI/UX events can complete) before we do our action.
Generally, whenever processing events, key presses, button clicks, and so forth, think about what needs to happen now and what needs to be queued for later.
In your case, you have a simple action, but, imagine something more complex such as a button click that triggers a page transition and a sort of 10000 records. The UI/UX is the user clicks the button and we want to see the button animate down and up fully before the action kicks off. If we did it during the event handler, the button may appear to be stuck in the down portion of the animation and the app will appear momentarily hang/crash. So, it is important to understand when we need to queue up actions.
Qt.callLater is one of the easiest ways to separate the UI/UX event and the user action and can improve the perceptual responsiveness of your application.

QWebEngineView Stadia game how to captured mouse

Run the Stadia game in QWebEngineView, in the stadia i got a message
it's possible to capture mouse?
here is my code
WebEngineView{
anchors.fill: parent
url: "https://stadia.google.com/"
onFullScreenRequested: function(request) {
request.accept()
}
}

Where QML camera.videoRecorder.record() save video file by default?

Where QML camera.videoRecorder.record() save video file by default ?
import QtQuick 2.2
import QtMultimedia 5.0
Item {
id:recoder
width:640
height:360
property bool rstat:true
function recordingSt(st)
{
if(st){
camera.videoRecorder.record() ;
st = false;
}else{
camera.videoRecorder.stop() ;
st = true;
}
}
MouseArea
{
anchors.fill: parent
onClicked:recordingSt(rstat)
}
Camera {
id: camera
videoRecorder.audioEncodingMode: CameraRecorder.ConstantBitrateEncoding
videoRecorder.audioBitRate: 48000
videoRecorder.mediaContainer: "mp4"
videoRecorder.frameRate: 25
}
VideoOutput {
source: camera
anchors.fill: parent
focus : visible // to receive focus and capture key events when visible
}
}
I am using Win8 OS have no idea where the video goes and how to set the path for recording . I tried
videoRecorder.outputLocation: "sameDirectory"
still not working why ?
From the documentation, it looks like you can set the location where you want to save by means of the properties imageCapture, which has the method captureToLocation.
It has also a property called capturedImagePath that maybe contains what you are looking for.
Look here and here and here for further details.
Sorry, just seen you were asking for the videoRecording.
It has the actualLocation property as well and it works as above, doesn't it?
The documentation states that that property holds the actual location of the last saved media content. Be aware that it's available once the recording starts, so you should look at it after the record method has been invoked.

Qml - ReferenceError: Screen is not defined

Trying to build a little fotball game as an project in school but I'm having some issues. So when I run the code it says that ReferenceError: Screen is not defined, but accordign to me I have defined it.
This code is just a prototype, going to change the keys to buttons later on so that it can actually work on a phone.
import QtQuick 2.0
Item {
id:root
width:Screen.width
height:Screen.height-10
focus:true
Keys.onPressed: {
if(event.key===Qt.Key_Up)
{
event.accepted = true;
player.y=(player.y) - 40
}
if(event.Key === Qt.Key_Down){
event.accepted = true;
player.y = (player.y)+ 40
}
if (event.key === Qt.Key_Right)
{ event.accepted=true;
player.x=(player.x)-40
}
if (event.key === Qt.Key_Left)
{event.accepted = true;
player.x=(player.x) +40
}
}
Flickable {
width:Screen.width
height:Screen.height
contentHeight: Screen.height*4
contentWidth:Screen.width
interactive:true
boundsBehavior: Flickable.StopAtBounds
Image{
id: feild
anchors.fill:parent
source:"Namnlös.png"
sourceSize.height:Screen.height*4
sourceSize.width:Screen.width
}
Image {
id: player
source:"asd.png"
x:Screen.width/2
y:Screen.height/2
}
}
}
So if you run this code you'll only get the player showing up, and then disapear instantly, the field is not shown.
You lack the Screen import.
import QtQuick.Window 2.1
Screen docs
Resizing items to screen is abnormal, you should simply use
resizeMode property
and anchor all child items inside root item.

Double click on buttons inside the app could provide UI corruptions

Double clicking fast on a button in Sencha Touch 2 when having a navigation view will on some Android device push the new view twice on the view stack, how to solve it? Doesnt happen on iPhone
If you're having problems with the single click, then wrap the event function in a delayed task... for instance:
tap: function(button, e, eOpts) {
if(this.delayedTask == null){
this.delayedTask = Ext.create('Ext.util.DelayedTask', function() {
this.myFunctionToCall();
this.delayedTask = null;
}, this);
this.delayedTask.delay(500);
}
}
So in the example above, if another tap is registered and this.delayedTask has yet to be null, then it will not create the new delayed task which ultimately calls whatever function you need after 500 miliseconds... hope this makes sense, it's also a way to create double tap events on buttons...
This issue is a bit old but I was facing the same issue in the app I'm working on in my company. This is especially frustrating when buttons are bound to an Ajax call.
I took back Jeff Wooden's solution to override every button in my app :
Ext.define('MyApp.override.CustomButton', {
override : 'Ext.Button',
doTap: function(me, e) {
if(this.delayedTask == null){
this.callOverridden(arguments);
this.delayedTask = Ext.create('Ext.util.DelayedTask', function() {
this.delayedTask = null;
}, this);
this.delayedTask.delay(500);
} else {
console.log("Preventing double tap");
}
}
});
How does it works?
Each button action will trigger a delayedTask which will intercept button action for 500 ms, therefore preventing doubletap
This will work for 'tap' and 'handler:', which both pass through 'doTap' method
this is linked to the current button so it won't reverberate on other buttons
To use it simply add it in your app.js 'requires' block
Ext.application({
requires: [
...
'MyApp.override.CustomButton',
...
],
Helpfull Sources :
https://www.sencha.com/forum/showthread.php?173374-Ext-override()-on-Ext-components-in-ExtJS-4-x
Best practice for overriding classes / properties in ExtJS?
this post