Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QFileDialog close my application
Qt 6.12 LTS is out! See what's new in the release blog

QFileDialog close my application

Scheduled Pinned Locked Moved Unsolved Qt for Python
7 Posts 3 Posters 2.4k 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.
  • X Offline
    X Offline
    Xav12358
    wrote on last edited by Xav12358
    #1

    Hello,

    I add to my program a QFileDialog window. When I close the file dialog window, the function keep executing the following command but at the end of the function the main window is closed and after the FileDialog.

    Here is my program:

    class Controller(QtWidgets.QWidget):
        view: View
        model: Model
    
        def __init__(self, model: Model, view: View):
            super(Controller, self).__init__()
    
    
        def open_datalog_folder(self, txt):
            print(txt)
            file_dialog = QFileDialog()
            try:
                directory = file_dialog.getOpenFileName(None, "Select directory")
                # file_dialog.blockSignals(True)
                print ('here')
            except:
                print("fzz")
                pass
    

    When I execute the program, I get the "Here" flag and the the program close. I try to block the signal from my file dialog quit event to avoid to send it to the lain window but it does work.

    jsulmJ 1 Reply Last reply
    0
    • X Xav12358

      Hello,

      I add to my program a QFileDialog window. When I close the file dialog window, the function keep executing the following command but at the end of the function the main window is closed and after the FileDialog.

      Here is my program:

      class Controller(QtWidgets.QWidget):
          view: View
          model: Model
      
          def __init__(self, model: Model, view: View):
              super(Controller, self).__init__()
      
      
          def open_datalog_folder(self, txt):
              print(txt)
              file_dialog = QFileDialog()
              try:
                  directory = file_dialog.getOpenFileName(None, "Select directory")
                  # file_dialog.blockSignals(True)
                  print ('here')
              except:
                  print("fzz")
                  pass
      

      When I execute the program, I get the "Here" flag and the the program close. I try to block the signal from my file dialog quit event to avoid to send it to the lain window but it does work.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Xav12358 said in QFileDialog close my application:

      getOpenFileName

      This is a static method: there is no need to create a QFileDialog instance to call it.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      X 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Xav12358 said in QFileDialog close my application:

        getOpenFileName

        This is a static method: there is no need to create a QFileDialog instance to call it.

        X Offline
        X Offline
        Xav12358
        wrote on last edited by
        #3

        @jsulm said in QFileDialog close my application:

        QFileDialog

        Than you for the tips. Indeed it is a static method, but I still have the same trouble.

        JonBJ 1 Reply Last reply
        0
        • X Xav12358

          @jsulm said in QFileDialog close my application:

          QFileDialog

          Than you for the tips. Indeed it is a static method, but I still have the same trouble.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Xav12358
          At the time you show the File Dialog do you have any other window/widget currently open/visible in your application? By default Qt widget applications are set to close and exit when the last visible window is closed, that might be your situation?

          X 1 Reply Last reply
          0
          • JonBJ JonB

            @Xav12358
            At the time you show the File Dialog do you have any other window/widget currently open/visible in your application? By default Qt widget applications are set to close and exit when the last visible window is closed, that might be your situation?

            X Offline
            X Offline
            Xav12358
            wrote on last edited by
            #5

            @JonB

            Indeed I have the mainwindows already open. How could I change the option you mention?

            JonBJ 1 Reply Last reply
            0
            • X Xav12358

              @JonB

              Indeed I have the mainwindows already open. How could I change the option you mention?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Xav12358
              Well if you have the main window already open as you just wrote then the file dialog close will not be the last visible window to close so this won't apply? But I was talking about QGuiApplication::setQuitOnLastWindowClosed(bool quit), which one can set to false.

              X 1 Reply Last reply
              1
              • JonBJ JonB

                @Xav12358
                Well if you have the main window already open as you just wrote then the file dialog close will not be the last visible window to close so this won't apply? But I was talking about QGuiApplication::setQuitOnLastWindowClosed(bool quit), which one can set to false.

                X Offline
                X Offline
                Xav12358
                wrote on last edited by
                #7

                @JonB

                It seems to work. Thank you.

                1 Reply Last reply
                0
                • SGaistS SGaist moved this topic from General and Desktop on

                • Login

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