I'm new to qt programming.so please go easy on me. I have one dialog designed in Qt5.4, A modal main Window or a dialog is to be opened when a button is pressed.but i can not find the setModal object to set the Qwindow and when i press the button the dialog dose not hid and neither the Qwindow or dialog will open. here are my codes

Login.h

Qt Code:
  1. #ifndef LOGIN_H
  2. #define LOGIN_H
  3.  
  4. #include <QDialog>
  5. #include <QCoreApplication>
  6. #include <QApplication>
  7. #include <QtSql/QSql>
  8. #include <QtSql/QSqlDatabase>
  9. #include <QtSql/QSqlDriver>
  10. #include <QtSql/QSqlQuery>
  11. #include <QDebug>
  12. #include "next_page.h"
  13. #include "main_page.h"
  14.  
  15. namespace Ui {
  16. class Login;
  17. }
  18.  
  19. class Login : public QDialog
  20. {
  21. Q_OBJECT
  22.  
  23. public:
  24. // function for database connetion
  25. QSqlDatabase MyDB; //object for connection
  26. /*
  27.   void CloseConncetion()
  28.   {
  29.   MyDB.close();
  30.   MyDB.removeDatabase(QSqlDatabase::defaultConnection);
  31.   }
  32. */
  33. void CloseConncetion()
  34. {
  35. QString connection;
  36. connection = MyDB.connectionName();
  37. MyDB=QSqlDatabase();
  38. MyDB.removeDatabase(connection);
  39. }
  40.  
  41.  
  42. bool OpenConncetion(){
  43. QSqlDatabase MyDB = QSqlDatabase::addDatabase("QMYSQL");
  44. MyDB .setHostName("localhost");
  45. MyDB.setDatabaseName("project");
  46. MyDB.setUserName("lord-ivan");
  47. MyDB.setPassword("Ir0ngo@t");
  48.  
  49. if (!MyDB.open())
  50. {
  51. qDebug()<<("Datebase not Connected");
  52.  
  53. return false;
  54.  
  55. }
  56. else
  57. {
  58. qDebug()<<("Datebase Connected");
  59.  
  60. return true;
  61. }
  62.  
  63. }
  64. public:
  65. explicit Login(QWidget *parent = 0);
  66. ~Login();
  67.  
  68. private slots:
  69. void on_pushButton_Login_clicked();
  70.  
  71. void on_pushButton_clicked();
  72.  
  73. private:
  74. Ui::Login *ui;
  75. };
  76.  
  77. #endif // LOGIN_H
To copy to clipboard, switch view to plain text mode 

Login.cpp

Qt Code:
  1. #include "login.h"
  2. #include "ui_login.h"
  3.  
  4. Login::Login(QWidget *parent) :
  5. QDialog(parent),
  6. ui(new Ui::Login)
  7. {
  8. ui->setupUi(this);
  9.  
  10.  
  11. if (!OpenConncetion())
  12. ui->label_Status->setText("Datebase not Connected");
  13. else
  14. ui->label_Status->setText("Datebase Connected");
  15.  
  16. }
  17.  
  18. Login::~Login()
  19. {
  20. delete ui;
  21. }
  22.  
  23. void Login::on_pushButton_Login_clicked()
  24. {
  25.  
  26.  
  27. QString username,password;
  28.  
  29. username=ui->lineEdit_UserName->text();
  30. password=ui->lineEdit_PassWord->text();
  31.  
  32. if(!OpenConncetion())
  33. {
  34. qDebug()<<"Datebase not Connected";
  35. return;
  36. }
  37.  
  38. QSqlQuery query;
  39.  
  40. if(query.exec("SELECT * FROM Users where UserName ='"+username+"' and Password ='"+password+"'")) // query for input
  41. {
  42. int count=0;
  43. while(query.next())
  44. {
  45.  
  46. count++;
  47. }
  48. if (count==1)
  49. {
  50. ui->label_Status->setText("Username and password is correct");
  51.  
  52. CloseConncetion(); // it is important to call this funcion to open the connection.
  53.  
  54. this->hide();
  55. Next_Page page;
  56. page.setModal(true);
  57. page.exec();
  58.  
  59. }
  60. if (count>1)
  61. ui->label_Status->setText("Duplicate Username and password is correct");
  62. if (count<1)
  63. ui->label_Status->setText("Username and password is not correct");
  64.  
  65.  
  66. }
  67.  
  68.  
  69.  
  70. }
  71.  
  72. void Login::on_pushButton_clicked()
  73. {
  74.  
  75.  
  76.  
  77. QString username,password;
  78.  
  79. username=ui->lineEdit_UserName->text();
  80. password=ui->lineEdit_PassWord->text();
  81.  
  82. if(!OpenConncetion())
  83. {
  84. qDebug()<<"Datebase not Connected";
  85. return;
  86. }
  87.  
  88. QSqlQuery query;
  89.  
  90. if(query.exec("SELECT * FROM Users where UserName ='"+username+"' and Password ='"+password+"'")) // query for input
  91. {
  92. int count=0;
  93. while(query.next())
  94. {
  95.  
  96. count++;
  97. }
  98. if (count==1)
  99. {
  100. ui->label_Status->setText("Username and password is correct");
  101.  
  102. CloseConncetion(); // it is important to call this funcion to open the connection.
  103.  
  104. this->hide();
  105. Main_Page Mpage;
  106. Mpage.window();
  107.  
  108. Mpage.show();
  109.  
  110. }
  111. if (count>1)
  112. ui->label_Status->setText("Duplicate Username and password is correct");
  113. if (count<1)
  114. ui->label_Status->setText("Username and password is not correct");
  115.  
  116.  
  117. }
  118. }
To copy to clipboard, switch view to plain text mode