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. QDialog and QMainWindow problem
Qt 6.11 is out! See what's new in the release blog

QDialog and QMainWindow problem

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.0k 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.
  • md2012M Offline
    md2012M Offline
    md2012
    wrote on last edited by md2012
    #1

    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();
    }
    
    
    joeQJ 1 Reply Last reply
    0
    • md2012M md2012

      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();
      }
      
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by
      #2

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

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

      Just do it!

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

        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.

        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
        1
        • joeQJ joeQ

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

          /** here your codes */
          
          void foo()
          {
          
          }
          
          md2012M Offline
          md2012M Offline
          md2012
          wrote on last edited by md2012
          #4

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

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

            Great !

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

            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
            1

            • Login

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