Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PyQt5 closeEvent reimplementation
Forum Updated to NodeBB v4.3 + New Features

PyQt5 closeEvent reimplementation

Scheduled Pinned Locked Moved Solved Language Bindings
20 Posts 3 Posters 14.7k Views 2 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #11

    Do you mean like QCommandLineParser ? Or Python's argparse module ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • U user4592357

      btw, is there a way to pass command line arguments to a deployed app (sounds surreal but im asking)?

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

      @user4592357
      What do you mean about deployed app & argument passing? If by any chance you mean can you pass arguments once the app is launched from the desktop via a shortcut, then yes. In general, your PyQt app's __main__ sees sys.argv like normal.

      U 1 Reply Last reply
      0
      • JonBJ JonB

        @user4592357
        What do you mean about deployed app & argument passing? If by any chance you mean can you pass arguments once the app is launched from the desktop via a shortcut, then yes. In general, your PyQt app's __main__ sees sys.argv like normal.

        U Offline
        U Offline
        user4592357
        wrote on last edited by user4592357
        #13

        @JonB,
        yes that's what i meant. i'll try that.

        @SGaist,
        should i reimplement __del__() for calling __write_settings()? the book which i use as a reference says that, "in all X classes presented in the book, none reimplements it"

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Can you give the reference ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply
          0
          • SGaistS SGaist

            Can you give the reference ?

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #15

            @SGaist
            https://fatima-python.wikispaces.com/file/view/Rapid+GUI+Programming+with+Python+and+Qt.pdf
            page 79 (book page, pdf page is 93)

            JonBJ 1 Reply Last reply
            0
            • U user4592357

              @SGaist
              https://fatima-python.wikispaces.com/file/view/Rapid+GUI+Programming+with+Python+and+Qt.pdf
              page 79 (book page, pdf page is 93)

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

              @user4592357
              I wouldn't put anything as complicated as saving settings in a destructor. Your closeEvent() sounded right for this. Why are we suddenly discussing __del__()?

              1 Reply Last reply
              0
              • SGaistS SGaist

                Personally, I usually write down settings in the destructor of a class rather than close event.

                As for your trace back, what are you doing in __write_settings ?

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #17

                Because of this:

                @SGaist said in PyQt5 closeEvent reimplementation:

                Personally, I usually write down settings in the destructor of a class rather than close event.

                That's what I do in C++.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ U 2 Replies Last reply
                0
                • SGaistS SGaist

                  Because of this:

                  @SGaist said in PyQt5 closeEvent reimplementation:

                  Personally, I usually write down settings in the destructor of a class rather than close event.

                  That's what I do in C++.

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

                  @SGaist
                  Ohhh, didn't see that.

                  Umm, far be it for me to disagree, but personally I wouldn't. I thought destructors were supposed to be cheap and have no side-effects. So many things can happen when saving settings. I wouldn't do it in C# FWIW, and I wouldn't do it in Python. (I also would not load settings in __init__().)

                  1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Because of this:

                    @SGaist said in PyQt5 closeEvent reimplementation:

                    Personally, I usually write down settings in the destructor of a class rather than close event.

                    That's what I do in C++.

                    U Offline
                    U Offline
                    user4592357
                    wrote on last edited by
                    #19

                    @SGaist
                    what about the book's statement?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #20

                      In the python case, that's indeed something debatable. Most of the time, people don't need to implement __del__.

                      What I would do is to store the settings once you close the corresponding dialog so that you avoid the trouble you had with the unintended interruption you have (unless it's done while the dialog is open).

                      In the extreme case, you can even save you settings on modification if you have an "apply immediately" without cancel style of application preferences.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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