QDialog and QMainWindow problem



  • hi guys ,im working on a project for my database lab but i faced a problem which i couldn't solve it by searching the internet so im asking it here.
    i have a QMainWindow for my program and a bunch of buttons that lunches my QDialogs.
    no matter what my QMainWindow bring it selfs on top after few seconds of lunching the dialogs and the dialogs classes wont work ,like push buttons or line eddits or whatever that is on the dialog .but if i close the MainWindow manually it will start working.
    i tired the setWindowFlag thing with always on top or bottom but it wont solve the dialog problem.

    my mainwindow

    SportClub::SportClub(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::SportClub)
    {
        ui->setupUi(this);
    }
    
    SportClub::~SportClub()
    {
        delete ui;
    }
    
    SportClub::sqlmanager::sqlmanager()
    {
        db = QSqlDatabase::addDatabase("QMYSQL");
            db.setHostName("localhost");
            db.setDatabaseName("gym_az");
            db.setUserName("gymqt");
            db.setPassword("784512");
            db.open();
    }
    
    bool SportClub::sqlmanager::is_database_open()
    {
            if(db.open())
            return true;
            else
                return false;
    }
    
    void SportClub::check_connection()
    {
        if(sc_db.is_database_open())
            ui->label_3->setText("ارتباط با پایگاه داده برقرار شد.");
        else
            ui->label_3->setText("ارتباط با پایگاه داده برقرار نشد.ارتباط خود با شبکه را بررسی کنید.");
    }
    
    void SportClub::on_pushButton_9_clicked()
    {
        close();
    }
    
    void SportClub::on_pushButton_10_clicked()
    {
        setWindowState(Qt::WindowMinimized);
    }
    
    void SportClub::on_pushButton_clicked()
    {
        clients a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_6_clicked()
    {
        staff a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_2_clicked()
    {
        instructors a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_3_clicked()
    {
        classes a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_4_clicked()
    {
        Equipements a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_5_clicked()
    {
        facility a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_7_clicked()
    {
        manager a;
        a.show();
        a.exec();
    }
    
    void SportClub::on_pushButton_11_clicked()
    {
        check_connection();
    }
    
    


  • @md2012 Hi, friend. when you show some code. you should use the following markdown format.

    /** here your codes */
    
    void foo()
    {
    
    }
    

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Don't call both show and exec on your dialog.

    exec will create a local even loop and block the main one while you interact with it.

    Also, please take a look at the QtSql examples. You are not using the QSqlDatabase class correctly.

    One last note, if you want to know whether the database has been opened there is the isOpen method.



  • @joeQ
    done :)

    @SGaist
    ThnQ sir ,my problem solved after removing the show() for the dialogs ,
    i wil take a look at the article you gave me for the SQL parts.


  • Lifetime Qt Champion

    Great !

    Then please mark the thread as solved using the "Topic Tools" button so other forum users may know a solution has been found :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.