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. Prevent Messagedialog from closing application
Forum Updated to NodeBB v4.3 + New Features

Prevent Messagedialog from closing application

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
messagedialogqml
5 Posts 3 Posters 515 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.
  • F Offline
    F Offline
    firen
    wrote on last edited by firen
    #1

    Hi,
    I deleted (sorry for deleting, guess thats not the right way) to early my old question, but anyway here again:

    Lets say I have one ApplicationWindow:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Controls.impl 2.3
    import QtQuick.Dialogs 1.1
    import QtCharts 2.3
    
    ApplicationWindow {
        id: applicationWindow1
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Loader{
            id:loader
        }
    
        Button {
            id: button
            x: 270
            y: 220
            text: qsTr("Button")
            onClicked:
            {
                applicationWindow1.visible = false;
                loader.source = "test123.qml";
            }
        }
    }
    

    And the otherone which is loaded:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Controls.impl 2.3
    import QtQuick.Dialogs 1.1
    import QtCharts 2.3
    
    ApplicationWindow {
        id: applicationWindow2
        width: 640
        height: 480
        visible: true
        title: qsTr("New")
    
    
        MessageDialog{
            id: analysisDone
            visible: true
            standardButtons: StandardButton.Ok
    
        }
    
    }
    

    What is the right way to prevent, that the closing of the Messagedialog closes the whole application?

    1 Reply Last reply
    0
    • IntruderExcluderI Offline
      IntruderExcluderI Offline
      IntruderExcluder
      wrote on last edited by
      #2

      Not sure what are you trying to achieve, but I do not think that having two ApplicationWindow instances in one application is an a good idea. If you want to show dialog by pressing button, you can have it defined in your first qml, just set it to unvisible:

      Button {
          onClicked: dlg.open()
      }
      
      MessageDialog {
          id: dlg
          visible: false
      }
      

      If you want to save a bit of memory, you can go in dynamic way, using Component, but make sure if you destroy your objects properly.

      GrecKoG 1 Reply Last reply
      0
      • IntruderExcluderI IntruderExcluder

        Not sure what are you trying to achieve, but I do not think that having two ApplicationWindow instances in one application is an a good idea. If you want to show dialog by pressing button, you can have it defined in your first qml, just set it to unvisible:

        Button {
            onClicked: dlg.open()
        }
        
        MessageDialog {
            id: dlg
            visible: false
        }
        

        If you want to save a bit of memory, you can go in dynamic way, using Component, but make sure if you destroy your objects properly.

        GrecKoG Online
        GrecKoG Online
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @IntruderExcluder said in Prevent Messagedialog from closing application:

        Not sure what are you trying to achieve, but I do not think that having two ApplicationWindow instances in one application is an a good idea.

        There's nothing special about ApplicationWindow, having 2 of them is not a problem.
        It's just a convenience class on top of Window with builtin support for header, footer and overlays.

        IntruderExcluderI 1 Reply Last reply
        0
        • GrecKoG GrecKo

          @IntruderExcluder said in Prevent Messagedialog from closing application:

          Not sure what are you trying to achieve, but I do not think that having two ApplicationWindow instances in one application is an a good idea.

          There's nothing special about ApplicationWindow, having 2 of them is not a problem.
          It's just a convenience class on top of Window with builtin support for header, footer and overlays.

          IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by IntruderExcluder
          #4

          @GrecKo Ok, but I do not know, why closing dialog causes application to quit, thats strange. 🤔

          1 Reply Last reply
          0
          • F Offline
            F Offline
            firen
            wrote on last edited by
            #5

            it seems that it is important which file is used in the engine

                QQmlApplicationEngine engine;
                engine.load(QUrl(QStringLiteral("qrc:/login.qml")));
            

            As long as i keep everything in this qml the behaviour is "normal". If I change to another ApplicationWindow with a loader I get the strange thinks.

            Maybe I have to change to a layout with only one ApplicationWindow

            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