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 to prevent open form?
Qt 6.11 is out! See what's new in the release blog

How to prevent open form?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.2k 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.
  • MucipM Offline
    MucipM Offline
    Mucip
    wrote on last edited by
    #1

    Hi,
    I use below code to open new UI form.

    mUrunAgacAl = new UrunAgacAl(this);
    mUrunAgacAl->showMaximized();
    

    I want to check authority of the user if he/she can open and use form?! In this case I check authorization in the setup section of the form before than below code;

    ui->setupUi(this);
    

    My code is:

    if(!auth){
            QMessageBox::warning(this,"No permission!", "You can not use this form Exiting...");        
            this->close();
            return;
        }
    

    But above code is not working. Form is still opening?!
    I tyed also ;

    this->destroy(true,true);
    

    But still openning but emty page!
    I just want to prevent opening form and delete from memort ofcourse?! How can I do it?
    Regards,
    Mucip:)

    jsulmJ 1 Reply Last reply
    0
    • MucipM Mucip

      Hi,
      I use below code to open new UI form.

      mUrunAgacAl = new UrunAgacAl(this);
      mUrunAgacAl->showMaximized();
      

      I want to check authority of the user if he/she can open and use form?! In this case I check authorization in the setup section of the form before than below code;

      ui->setupUi(this);
      

      My code is:

      if(!auth){
              QMessageBox::warning(this,"No permission!", "You can not use this form Exiting...");        
              this->close();
              return;
          }
      

      But above code is not working. Form is still opening?!
      I tyed also ;

      this->destroy(true,true);
      

      But still openning but emty page!
      I just want to prevent opening form and delete from memort ofcourse?! How can I do it?
      Regards,
      Mucip:)

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

      @Mucip Why not

      if(auth){
          mUrunAgacAl = new UrunAgacAl(this);
          mUrunAgacAl->showMaximized();
      } else {
          QMessageBox::warning(this,"No permission!", "You can not use this form Exiting...");
      }
      

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

      MucipM 1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Dont do it in the constructor.
        Its too late there. Object being constructed at that moment.
        so be much better if you did BEFORE creating the UrunAgacAl.

        MucipM 1 Reply Last reply
        2
        • jsulmJ jsulm

          @Mucip Why not

          if(auth){
              mUrunAgacAl = new UrunAgacAl(this);
              mUrunAgacAl->showMaximized();
          } else {
              QMessageBox::warning(this,"No permission!", "You can not use this form Exiting...");
          }
          
          MucipM Offline
          MucipM Offline
          Mucip
          wrote on last edited by
          #4

          Dear @jsulm ,
          In this case I need to control for every form. In the beginning I don't know the ID of the form. But If I can make the form self control then it will be much esaier for me unfortunatelly!... :(

          Regards,
          Mucip:)

          1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Dont do it in the constructor.
            Its too late there. Object being constructed at that moment.
            so be much better if you did BEFORE creating the UrunAgacAl.

            MucipM Offline
            MucipM Offline
            Mucip
            wrote on last edited by
            #5

            Dear @mrjj ,
            It's very difficult for me! It's better to make this control to form own!..

            Regards,
            Mucip:)

            jsulmJ 1 Reply Last reply
            0
            • MucipM Mucip

              Dear @mrjj ,
              It's very difficult for me! It's better to make this control to form own!..

              Regards,
              Mucip:)

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

              @Mucip In my opinion it is a bad idea to let each form to decide whether it should be shown or not. This decision should be taken (ideally) in one place.

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

              1 Reply Last reply
              3
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                I agree with its not the best way but lets say we must do it.

                I was wondering cant you do like
                mUrunAgacAl = new UrunAgacAl(this);
                if (! UrunAgacAl->auth ) {
                mUrunAgacAl->close();
                mUrunAgacAl->deletelater();
                } else
                mUrunAgacAl->showMaximized();

                1 Reply Last reply
                0
                • MucipM Offline
                  MucipM Offline
                  Mucip
                  wrote on last edited by
                  #8

                  Hi,
                  OK. I will change the style as you said before than open command.

                  Regards,
                  Mucip:)

                  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