[Solved] Closing a dialog with a timer.
hi i am new to the community. please tell me how to start a new thread. as for your reply, thanks a lot. but you could not understand my problem clearly. let me tell you in detail. i am building a mobile examination system. i have first dialog box that displays the instruction before the start of the examination. i have made 25 questions each question to be answered by clicking a radiobutton & pushbutton by which it is possible to navigate to the next page. as soon as the pushbutton is clicked on the “instruction dialog”, a timer is started. a timer may be expired while the candidate is taking the examination. the candidate may have answered all or few questions only. which means that while the candidate is giving the examination & is reading the question on a particular “question dialog”, the timer may be expired. then i want that when timer is exited, all the other open dialogs get closed automatically. i am providing the code for my file here:- #include "mydialog2.h"
- #include "ui_mydialog2.h"
- #include "mydialog3.h"
- #include<QTimer>
- #include "mydialog29.h"
- #include"timeout.h"
- ui(new Ui::MyDialog2)
- {
- ui->setupUi(this);
- }
- MyDialog2::~MyDialog2()
- {
- delete ui;
- }
- void MyDialog2::on_pushButton_2_clicked()
- {
- connect(&timer,SIGNAL(timeout()),this,SLOT(MySlot()));
- this->timer.start(10000);
- MyDialog3 mDialog3;
- mDialog3.setModal(true);
- mDialog3.exec();
- }
- void MyDialog2::MySlot()
- {
- this->timer.stop();
- timeout t;
- t.setModal(true);
- t.exec();
- }
- #include "mydialog3.h"
- #include "ui_mydialog3.h"
- #include "mydialog4.h"
- #include<QAbstractButton>
- ui(new Ui::MyDialog3)
- {
- ui->setupUi(this);
- }
- MyDialog3::~MyDialog3()
- {
- db.close();
- delete ui;
- }
- void MyDialog3::on_pushButton_clicked()
- {
- db.setDatabaseName("prject3");
- db.open();
- QSqlQuery q;
- q.exec("create table reslt1(quesno char(5),optionclicked char(15),correctans char(3),marks integer(2));");
- if(!(ui->radioButton->isChecked()) && !(ui->radioButton_2->isChecked()) && !(ui->radioButton_3->isChecked())&& !(ui->radioButton_4->isChecked()))
- {
- q.exec("insert into reslt1 values('Q1','Unanswered','A',0);");
- }
- else
- {
- if(ui->radioButton->isChecked())
- {
- q.exec("insert into reslt1 values('Q1','A','A',1);");
- }
- if(ui->radioButton_2->isChecked())
- {
- q.exec("insert into reslt1 values('Q1','B','A',0);");
- }
- if(ui->radioButton_3->isChecked())
- {
- q.exec("insert into reslt1 values('Q1','C','A',0);");
- }
- if(ui->radioButton_4->isChecked())
- {
- q.exec("insert into reslt1 values('Q1','D','A',0);");
- }
- }
- MyDialog4 mDialog4;
- mDialog4.setModal(true);
- mDialog4.exec();
- }
- #include "timeout.h"
- #include "ui_timeout.h"
- #include"result.h"
- ui(new Ui::timeout)
- {
- ui->setupUi(this);
- }
- timeout::~timeout()
- {
- delete ui;
- }
- void timeout::on_pushButton_clicked()
- {
- Result r;
- r.setModal(true);
- r.exec();
- }
***“What i want is that when result form is opened on click of pushbutton or when timer is stopped in MySlot(), the opened mydialog3 also gets closed automatically”*
**
[Edit: Added @ tags for code; mlong]
15 replies
While creating the Widget, if you pass in the parent widget as argument, it would be the parent. Is that what you are asking for?
- timeout t;
- MyDialog3 dlg3(&t); // dlg3's parent would be t
You can use setParent() [qt-project.org] to set the parent of widget independently, would suggest to go through the manual for Note & Warning.
Is this what you asked for?
1) how to pass value from a lineedit in gui to the backend database for storage
lineedit will have a method text() to return whatever entered in lineedit – use this to send to backend database
2) how to start a new thread in the community
Under Forums -> Qt Development -> General and Desktop -> Start new discussion [qt-project.org]
3) how to use setParent() function
Warning: It is very unlikely that you will ever need this function – If you can set the parent while creation, that will be okay.
thank a lot for the suggestion. but i have already tried this out. i give mu coding for the form below:
- #include "mydialog.h"
- #include "ui_mydialog.h"
- #include <QtCore>
- #include <QtGui>
- #include <QtSql>
- #include"user_data.h"
- #include "mydialog30.h"
- ui(new Ui::MyDialog)
- {
- ui->setupUi(this);
- }
- MyDialog::~MyDialog()
- {
- db.close();
- delete ui;
- }
- void MyDialog::on_pushButton_5_clicked()
- {
- if((ui->lineEdit_13->isModified())&& (ui->lineEdit_14->isModified())&&(ui->lineEdit_15->isModified())&&(ui->lineEdit_16->isModified())&&(ui->lineEdit_17->isModified())&& (ui->lineEdit_18->isModified()))
- {
- db.setDatabaseName("prject3");
- db.open();
- QSqlQuery q;
- q.exec("create table tab1(name char(10),branch char(5),dob char(6),contact number(10),email_id char(10),address char(10));");
- q.exec("insert into tab1 values('ui->lineEdit_14->text()','ui->lineEdit_13->text()','ui->lineEdit_15->text()','ui->lineEdit_16->text()','ui->lineEdit_17->text()','ui->lineEdit_18->text()');");
- user_data d;
- d.exec();
- }
- else
- {
- MyDialog30 m;
- m.exec();
- }
- }
here the problem is that the input is getting accepted perfectly well on using text() function of line edit. but when i am passing it into the database & displaying the output, the output is not being displayed. i am posting here the coding for my form showing the output also here:
- #include "user_data.h"
- #include "ui_user_data.h"
- #include"mydialog28.h"
- ui(new Ui::user_data)
- {
- ui->setupUi(this);
- }
- user_data::~user_data()
- {
- db.close();
- delete ui;
- }
- void user_data::on_pushButton_clicked()
- {
- MyDialog28 m;
- m.exec();
- }
- void user_data::on_pushButton_2_clicked()
- {
- }
- void user_data::on_pushButton_3_clicked()
- {
- db.setDatabaseName("prject3");
- db.open();
- model->setQuery("select * from tab1");
- ui->tableView->setModel(model);
- }
[Edit: @ tags; mlong]
please tell the solution to my problem
I don’t have an answer, myself, but I promise that making demands such as that is considered rude and will not help you get an answer faster.
Please see http://www.catb.org/~esr/faqs/smart-questions.html for advice on how to get the best results. Thanks.
Try the below
- q.exec( query );
I would strongly suggest you to go through the documentation for QString [qt-project.org]. Infact you can click on the source code [highlighted with GREEN color] to go to the documentation page.
You must log in to post a reply. Not a member yet? Register here!



