Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how do something on a window before the user open that window?
Qt 6.11 is out! See what's new in the release blog

how do something on a window before the user open that window?

Scheduled Pinned Locked Moved Solved General and Desktop
35 Posts 5 Posters 6.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #20

    @mrjj @JonB
    this is my dialog
    0_1534424096209_336e2a13-d316-471c-8b82-b5c8b2f80d91-image.png

    this is doAll()
    0_1534424167621_f244dbec-bdff-46a1-b9a4-1582fd9e8325-image.png

    it suppose to execute doall(true) when admin password is right .OK?
    so doAll must be false when the window shows
    so the user will be have to fill admin password

    JonBJ 1 Reply Last reply
    0
    • ? A Former User

      @mrjj @JonB
      this is my dialog
      0_1534424096209_336e2a13-d316-471c-8b82-b5c8b2f80d91-image.png

      this is doAll()
      0_1534424167621_f244dbec-bdff-46a1-b9a4-1582fd9e8325-image.png

      it suppose to execute doall(true) when admin password is right .OK?
      so doAll must be false when the window shows
      so the user will be have to fill admin password

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

      @davidlabib
      I think you're saying you want all the other other widgets to be enabled/disabled depending on whether Admin Password has or has not been filled in correctly? Or according as it has something/nothing already in it?

      If that is the case you will want to disable/enable as user types into Admin Password? So you will also want to call this during input to that widget? Do you also (sometimes) put something into Admin Password when you display the dialog?

      All in all, why do you only seem to want to call doAll() when window is shown? And you need to answer @mrjj's question: Yes, we can see your dialog, but that does not tell us whether you keep it in existence after showing it or whether you destroy it and construct from scratch?

      I'll give you one tip. I have code which must only be executed the first time a window/dialog is shown, not before then (construction time is too early) and not after then. So my code for showEvent() is like (I don't use C++):

      classMemberVarialbeFirstShown = false;
      
      showEvent()
      {
          if not classMemberVarialbeFirstShown
              doFirstImeStuff();
          classMemberVarialbeFirstShown = true;
      }
      
      1 Reply Last reply
      2
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #22

        @mrjj no , i don't have to keep it in existence
        i don't mind destroying and re-creating it

        mrjjM JonBJ 2 Replies Last reply
        0
        • ? A Former User

          @mrjj no , i don't have to keep it in existence
          i don't mind destroying and re-creating it

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #23

          @davidlabib
          Ok so im not sure what its not working for you
          If you call doAll(false) in constructor
          then when Dialog is shown they should all be disabled.
          Is that not the case?

          1 Reply Last reply
          1
          • ? A Former User

            @mrjj no , i don't have to keep it in existence
            i don't mind destroying and re-creating it

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

            @davidlabib
            Then you could follow @mrjj's advice to just do your work in the constructor and not worry about show events.

            But you really need to explain precisely when you want those widgets to change between enabled & disabled, because I for one don't know what you intend.

            1 Reply Last reply
            1
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #25

              the default is disabled
              but when the user input admin password correct it will enabled the widgets
              my problem is to make the widgets disabled by default
              if i put doAll(false) in the constructor when soneone fill admin password correct it will enable
              but if the user closed editUser and open it again it will be enabled without admin password filling

              JonBJ 1 Reply Last reply
              0
              • ? A Former User

                the default is disabled
                but when the user input admin password correct it will enabled the widgets
                my problem is to make the widgets disabled by default
                if i put doAll(false) in the constructor when soneone fill admin password correct it will enable
                but if the user closed editUser and open it again it will be enabled without admin password filling

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

                @davidlabib

                but when the user input admin password correct it will enabled the widgets

                When? Do you re-verify the password as he types each character into the line edit?

                my problem is to make the widgets disabled by default

                Put the disablement into the constructor.

                if i put doAll(false) in the constructor when soneone fill admin password correct it will enable

                It will not enable unless you tell it to.

                but if the user closed editUser and open it again it will be enabled without admin password filling

                That is the bit where @mrjj was suggesting you destroy the dialog after using it, and re-create a new one each time it's wanted. Then there is no "open again" from wherever it got to, you always start afresh in the constructor.

                1 Reply Last reply
                2
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #27
                  1. Yes , verify the password
                  2. I don't know how to destroy the dialog after the user close the window
                  JonBJ 1 Reply Last reply
                  0
                  • ? A Former User
                    1. Yes , verify the password
                    2. I don't know how to destroy the dialog after the user close the window
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #28

                    @davidlabib

                    1.Yes , verify the password

                    That does not answer my question. When do you verify the password? As the user types a character at a time (really?)? After he has finished typing (how do you know that?)?

                    2.I don't know how to destroy the dialog after the user close the window

                    How do you create the dialog in the first place? With new?

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by A Former User
                      #29

                      @JonB

                      1. the form will enable after the user type all the character correctly without clicking buttons
                        after he type the last char correct it will enable the window

                      2. by qt designer form class

                      jsulmJ JonBJ 2 Replies Last reply
                      0
                      • ? A Former User

                        @JonB

                        1. the form will enable after the user type all the character correctly without clicking buttons
                          after he type the last char correct it will enable the window

                        2. by qt designer form class

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

                        @davidlabib said in how do something on a window before the user open that window?:

                        after he type the last char

                        how do you know that? What if user enters correct password but then he/she enters one more character?
                        "by qt designer form class" - this is not the answer to the question. The question is: how do you create the dialog INSTANCE.
                        Like this:

                        MyDialog *dialog = new MyDialog(this);
                        

                        ?

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

                        1 Reply Last reply
                        2
                        • ? A Former User

                          @JonB

                          1. the form will enable after the user type all the character correctly without clicking buttons
                            after he type the last char correct it will enable the window

                          2. by qt designer form class

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

                          @davidlabib
                          Further to @jsulm.

                          If you do indeed check the password charaacter by character as it's typed, you will need to have a signal/slot for that and call doAll(True) whenever it becomes correct and doAll(False) if it then becomes incorrect. That's how you will do the enablement/disablement dynamically at runtime. I think you asked about that. Note that there's still nothing here about "when the dialog is shown", this is something which must be re-done on each character typed.

                          You will create the dialog in one of two ways:

                          • If you use new (creates on the heap), you will use delete (or .deleteLater()) to delete it.
                          • If you have it as a local variable (not a pointer) in a function it will be on the stack, and it will get destroyed when that function goes out of scope.

                          In either of these two cases you will be re-creating/destroying the dialog each time it is used, and so the constructor can be used to reset the initial state without worrying about when the dialog is "shown".

                          ? 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @davidlabib
                            Further to @jsulm.

                            If you do indeed check the password charaacter by character as it's typed, you will need to have a signal/slot for that and call doAll(True) whenever it becomes correct and doAll(False) if it then becomes incorrect. That's how you will do the enablement/disablement dynamically at runtime. I think you asked about that. Note that there's still nothing here about "when the dialog is shown", this is something which must be re-done on each character typed.

                            You will create the dialog in one of two ways:

                            • If you use new (creates on the heap), you will use delete (or .deleteLater()) to delete it.
                            • If you have it as a local variable (not a pointer) in a function it will be on the stack, and it will get destroyed when that function goes out of scope.

                            In either of these two cases you will be re-creating/destroying the dialog each time it is used, and so the constructor can be used to reset the initial state without worrying about when the dialog is "shown".

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by
                            #32

                            @JonB about the last 10 sentences i solved the problem thanks to you.
                            But about the first part
                            Yes it's signal and slot but
                            The widgets is enabled
                            And the user will not have to fill any thing in admin password field to do the slot
                            So it must disabled from the beginning

                            JonBJ 1 Reply Last reply
                            0
                            • ? A Former User

                              @JonB about the last 10 sentences i solved the problem thanks to you.
                              But about the first part
                              Yes it's signal and slot but
                              The widgets is enabled
                              And the user will not have to fill any thing in admin password field to do the slot
                              So it must disabled from the beginning

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

                              @davidlabib said in how do something on a window before the user open that window?:

                              So it must disabled from the beginning

                              Yes, that's why we already said you should call doAll(False) in the contructor so that it starts out disabled, plus call doAll(True)/doAll(False) again as appropriate as each character is typed.

                              1 Reply Last reply
                              2
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #34

                                @JonB i wasn't know how to do that
                                I seted the disable function in the constructor
                                and when i was closing the window and open it again doAll wasn't executing
                                Iam using "new" by the way
                                So it wasn't destroy the dialog
                                When i close it
                                But now i use delete

                                JonBJ 1 Reply Last reply
                                0
                                • ? A Former User

                                  @JonB i wasn't know how to do that
                                  I seted the disable function in the constructor
                                  and when i was closing the window and open it again doAll wasn't executing
                                  Iam using "new" by the way
                                  So it wasn't destroy the dialog
                                  When i close it
                                  But now i use delete

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

                                  @davidlabib
                                  So now you are using new & delete each time you want to show the dialog you should be finding it is correctly calling the constructor to set disabled at the start of every time it gets shown, right?

                                  More worrying is that you say you were using new but not delete. If you only call the new once and then keep the dialog around and reuse it it's not too bad. But if you keep calling a new and never call a corresponding a delete or .deleteLater() your code will "leak memory" by having separate instances of the dialog sitting around in memory unused forever. If you did not know this it's very important you understand how Qt expects you to code when creating widgets with new. Just saying.

                                  1 Reply Last reply
                                  2

                                  • Login

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