Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Design Tooling
  3. Qt Design Studio
  4. Dialog not working when i try to call every 6 second ?
Forum Updated to NodeBB v4.3 + New Features

Dialog not working when i try to call every 6 second ?

Scheduled Pinned Locked Moved Unsolved Qt Design Studio
2 Posts 2 Posters 513 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mariappanM Offline
    mariappanM Offline
    mariappan
    wrote on last edited by
    #1

    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.3

    ApplicationWindow {
    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.3

    ApplicationWindow {
    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"
            }
        }
    }
    

    }

    jeremy_kJ 1 Reply Last reply
    0
    • mariappanM mariappan

      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.3

      ApplicationWindow {
      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.3

      ApplicationWindow {
      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"
              }
          }
      }
      

      }

      jeremy_kJ Online
      jeremy_kJ Online
      jeremy_k
      wrote on last edited by
      #2

      @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.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved