Dialog not working when i try to call every 6 second ?
-
how to create Dialog in qml using qml designer tool ?
This is piece of code i have to display the dialog after every 6 seconds i see function getting called but no dialog button shoots up .I tried using qml designer i didnt find any diaglog elements . how to add dialogue to assoicate with the code below using qml designer studio ?/*import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Dialogs 1.3ApplicationWindow {
visible: true
width: 400
height: 300
title: "Task Tracker"Timer { id: minuteTimer interval: 1000 * 6 // 6 seconds in milliseconds onTriggered: { showTaskEntryDialog() } running: true repeat: true } function showTaskEntryDialog() { console.log("showTaskEntryDialog called") var dialog = taskInputDialog.createObject() dialog.accepted.connect(function() { if (dialog.taskInput.text !== "") { saveTaskToFile(dialog.taskInput.text) } dialog.destroy() }) dialog.rejected.connect(function() { dialog.destroy() }) } Rectangle { width: parent.width height: parent.height // You can add more UI elements here if needed Text { anchors.centerIn: parent text: "Task Tracker - Minute notifications" font.pixelSize: 18 } } Component { id: taskInputDialog Dialog { id: dialog x: 100 y: 100 width: 300 height: 100 title: qsTr("Enter Completed Task") standardButtons: Dialog.Ok | Dialog.Cancel TextField { id: taskInput width: parent.width - 20 placeholderText: "Enter the completed task" } } }
}
*/import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Dialogs 1.3ApplicationWindow {
visible: true
width: 400
height: 300
title: "Test Dialog Component"Button { text: "Show Dialog" onClicked: { var dialog = taskInputDialog.createObject() dialog.accepted.connect(function() { if (dialog.taskInput.text !== "") { console.log("Entered task:", dialog.taskInput.text); } dialog.destroy(); }) dialog.rejected.connect(function() { dialog.destroy(); }) } } Component { id: taskInputDialog Dialog { id: dialog width: 300 title: "Enter Task" standardButtons: Dialog.Ok | Dialog.Cancel TextField { id: taskInput width: parent.width - 20 placeholderText: "Enter a task" } } }
}
-
@mariappan said in Dialog not working when i try to call every 6 second ?:
var dialog = taskInputDialog.createObject()
The Dialog needs a parent, or a reference that will last as long as the object.
https://doc.qt.io/qt-6/qml-qtqml-component.html#createObject-method
If a parent is not provided to createObject(), a reference to the returned object must be held so that it is not destroyed by the garbage collector.