Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. replacing dialog with "regular" display
Forum Update on Monday, May 27th 2025

replacing dialog with "regular" display

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 2 Posters 702 Views
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I've been tasked with altering an app. Current behavior is, when a button is pressed on a particular page, to display a dialog with two buttons (run now and run later). If "run now" is selected, an action occurs; if "run later" is selected, another dialog with a calendar and clock appears for the user to set the desired run time.

    The customer wants to eliminate dialogs, and simply show full screen pages. The current implementation is this:

        var component = Qt.createComponent("start_now_or_later.qml")
        var nowOrLater = component.createObject(this)
        nowOrLater.accepted.connect(function () {
          if (nowOrLater.getStartNow()) {
        ...
    

    So, first question would be, if I eliminate the dialog, what is the mechanism for connecting the buttons in start_now_or_later.qml to the function above? In fact, do I even need a function, or should I just eliminate that page and display the buttons here?

    Thanks...

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      "accepted" looks like a signal in start_now_or_later.qml.
      Is that what you are asking?

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      0
      • fcarneyF fcarney

        "accepted" looks like a signal in start_now_or_later.qml.
        Is that what you are asking?

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @fcarney not exactly. Accepted() is a signal provided by the QML Dialog type:

        QML Dialog accepted()

        I'm wondering:

        1. what the non-dialog equivalent to this is, and
        2. if I should even be bothering with signals/slots if I'm going to eliminate the dialog.

        Thanks...

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          Then what is in start_now_or_later.qml?

          I create some of my own "dialogs" based upon Window. I use similar signals to control the lifetime of the Window.

          C++ is a perfectly valid school of magic.

          mzimmersM 1 Reply Last reply
          0
          • fcarneyF fcarney

            Then what is in start_now_or_later.qml?

            I create some of my own "dialogs" based upon Window. I use similar signals to control the lifetime of the Window.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @fcarney start_now_or_later.qml currently contains the definition of the dialog that I want to replace. If I change the Dialog to Rectangle, and try to run it without further changes, I get a warning at the accepted.connect:

            [QT-warning][v-c6ae7a2][thr:12986]qrc:/qml/DelayedStart.qml(18): qrc:/qml/DelayedStart.qml:18: TypeError: Cannot call method 'connect' of undefined
            

            Which makes sense, because I'm not supplying anything to signal a button push (I think). I need to know how to connect these buttons, now that they're not part of a Dialog.

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by fcarney
              #6
              Rectangle {
                id: rect
                signal accepted() // or put a param in there if required
              
                Button {
                  onTriggered: {
                    rect.accepted()
                  }
                }
              }
              

              C++ is a perfectly valid school of magic.

              mzimmersM 1 Reply Last reply
              2
              • fcarneyF fcarney
                Rectangle {
                  id: rect
                  signal accepted() // or put a param in there if required
                
                  Button {
                    onTriggered: {
                      rect.accepted()
                    }
                  }
                }
                
                mzimmersM Offline
                mzimmersM Offline
                mzimmers
                wrote on last edited by
                #7

                @fcarney thanks for that. Currently, when the app runs, I get a warning:

                unknown(0): QQmlComponent: Component is not ready
                

                According to some other threads, this suggests the application can't find a file, but this used to work. Is there another cause of this warning?

                Thanks...

                1 Reply Last reply
                0
                • fcarneyF Offline
                  fcarneyF Offline
                  fcarney
                  wrote on last edited by
                  #8

                  @mzimmers said in replacing dialog with "regular" display:

                  createComponent

                  https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-a-component-dynamically

                  Look at the function in that section called: createSpriteObjects. It shows how to delay createObject call if component is not ready.

                  C++ is a perfectly valid school of magic.

                  mzimmersM 1 Reply Last reply
                  1
                  • fcarneyF fcarney

                    @mzimmers said in replacing dialog with "regular" display:

                    createComponent

                    https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html#creating-a-component-dynamically

                    Look at the function in that section called: createSpriteObjects. It shows how to delay createObject call if component is not ready.

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #9

                    @fcarney interesting. Here's the code that you mentioned:

                    var component;
                    var sprite;
                    
                    function createSpriteObjects() {
                        component = Qt.createComponent("Sprite.qml");
                        if (component.status == Component.Ready)
                            finishCreation();
                        else
                            component.statusChanged.connect(finishCreation);
                    }
                    
                    function finishCreation() {
                        if (component.status == Component.Ready) {
                            sprite = component.createObject(appWindow, {x: 100, y: 100});
                            if (sprite == null) {
                                // Error Handling
                                console.log("Error creating object");
                            }
                        } else if (component.status == Component.Error) {
                            // Error Handling
                            console.log("Error loading component:", component.errorString());
                        }
                    }
                    

                    This explains a lot, but I don't see the delay that you mention...or was I supposed to add that myself?

                    This is beginning to add up for me...thanks for the help.

                    fcarneyF 1 Reply Last reply
                    0
                    • mzimmersM mzimmers

                      @fcarney interesting. Here's the code that you mentioned:

                      var component;
                      var sprite;
                      
                      function createSpriteObjects() {
                          component = Qt.createComponent("Sprite.qml");
                          if (component.status == Component.Ready)
                              finishCreation();
                          else
                              component.statusChanged.connect(finishCreation);
                      }
                      
                      function finishCreation() {
                          if (component.status == Component.Ready) {
                              sprite = component.createObject(appWindow, {x: 100, y: 100});
                              if (sprite == null) {
                                  // Error Handling
                                  console.log("Error creating object");
                              }
                          } else if (component.status == Component.Error) {
                              // Error Handling
                              console.log("Error loading component:", component.errorString());
                          }
                      }
                      

                      This explains a lot, but I don't see the delay that you mention...or was I supposed to add that myself?

                      This is beginning to add up for me...thanks for the help.

                      fcarneyF Offline
                      fcarneyF Offline
                      fcarney
                      wrote on last edited by
                      #10

                      @mzimmers If component is not ready it connect it to a signal. This delays the execution of createObject to when it is actually ready.

                      C++ is a perfectly valid school of magic.

                      mzimmersM 1 Reply Last reply
                      0
                      • fcarneyF fcarney

                        @mzimmers If component is not ready it connect it to a signal. This delays the execution of createObject to when it is actually ready.

                        mzimmersM Offline
                        mzimmersM Offline
                        mzimmers
                        wrote on last edited by
                        #11

                        @fcarney so, how should I "gate" the processing of the rest of the code:

                            nowOrLater.accepted.connect(function () {
                            if (nowOrLater.getStartNow()) {
                            ...
                        

                        I could put it in my finishCreation() function, but that doesn't seem quite right.

                        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