Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to prevent open form?



  • 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:)


  • Qt Champions 2019

    @Mucip Why not

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

  • Lifetime Qt Champion

    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.



  • 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:)



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

    Regards,
    Mucip:)


  • Qt Champions 2019

    @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.


  • Lifetime Qt Champion

    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();



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

    Regards,
    Mucip:)


Log in to reply