[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"
    MyDialog2::MyDialog2(QWidget *parent) :
    QDialog(parent),
    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();
    }
    @
    coding for mydialog 3 is as:
    @
    #include "mydialog3.h"
    #include "ui_mydialog3.h"
    #include "mydialog4.h"
    #include<QAbstractButton>
    MyDialog3::MyDialog3(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyDialog3)
    {
    ui->setupUi(this);
    }

    MyDialog3::~MyDialog3()
    {
    db.close();
    delete ui;
    }

    void MyDialog3::on_pushButton_clicked()
    {
    QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
    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&#40;"insert into reslt1 values('Q1','Unanswered','A',0&#41;;"&#41;;
    }
    else
    {
        if(ui->radioButton->isChecked(&#41;&#41;
        {
            q.exec&#40;"insert into reslt1 values('Q1','A','A',1&#41;;"&#41;;
    
        }
        if(ui->radioButton_2->isChecked(&#41;&#41;
        {
            q.exec&#40;"insert into reslt1 values('Q1','B','A',0&#41;;"&#41;;
        }
        if(ui->radioButton_3->isChecked(&#41;&#41;
        {
            q.exec&#40;"insert into reslt1 values('Q1','C','A',0&#41;;"&#41;;
        }
        if(ui->radioButton_4->isChecked(&#41;&#41;
        {
            q.exec&#40;"insert into reslt1 values('Q1','D','A',0&#41;;"&#41;;
        }
    }
    MyDialog4 mDialog4;
    mDialog4.setModal(true&#41;;
    mDialog4.exec(&#41;;
    

    }
    @
    coding for timeout is as:
    @
    #include "timeout.h"
    #include "ui_timeout.h"
    #include"result.h"

    timeout::timeout(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::timeout)
    {
    ui->setupUi(this);
    }

    timeout::~timeout()
    {
    delete ui;
    }

    void timeout::on_pushButton_clicked()
    {
    Result r;
    r.setModal(true);
    r.exec();
    }
    @
    so, say person was on mydialog 3 when timer expires. a message will be displayed that will indicate that timer has expired in form of timeout & clicking the pushbutton opens the result form.

    **"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]


  • Moderators

    I split the question into its own thread. Please start new threads for new topics.

    In response to your question though, every QDialog has an accept(), reject(), and done() slot, any of which can be connected to the timeout() signal of a QTimer.



  • for solving my problem i wanted that all the "Question dialogs" be ,ade child of either timeout dialog or the mydialog2. so that whenever they exit, it is possible to close all the open dialogs.

    but i dont know how to make one dialog child/parent of other. please help me o this.



  • 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()":http://qt-project.org/doc/qt-4.8/qwidget.html#setParent to set the parent of widget independently, would suggest to go through the manual for Note & Warning.

    Is this what you asked for?



  • thanks brother. thanks a lot. my problem is solved................
    please tell me the following things:

    1. how to pass value from a lineedit in gui to the backend database for storage
    2. how to start a new thread in the community
    3. how to use setParent() function


  • bq. 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

    bq. 2) how to start a new thread in the community

    Under Forums -> Qt Development -> General and Desktop -> "Start new discussion":http://qt-project.org/forums/viewforum/10/

    bq. 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"

    MyDialog::MyDialog(QWidget *parent) :
    QDialog(parent),
    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()))
    {
    QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
    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));");
    QString name= ui->lineEdit_14->text();
    QString branch= ui->lineEdit_13->text();
    QString date= ui->lineEdit_15->text();
    QString cnct =ui->lineEdit_16->text();
    QString email= ui->lineEdit_17->text();
    QString addrss= ui->lineEdit_18->text();
    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"
    user_data::user_data(QWidget *parent) :
    QDialog(parent),
    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()
    {
    QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("prject3");
    db.open();
    this->model= new QSqlQueryModel();
    model->setQuery("select * from tab1");
    ui->tableView->setModel(model);
    }
    @
    please help me out on how i can store a value of text entered through line edit into my backend database.

    [Edit: @ tags; mlong]


  • Moderators

    When posting code, please wrap it in @ tags to preserve its formatting.



  • sure sir. i will. please tell the solution to my problem.


  • Moderators

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



  • sorry sir for my bit of impatient behavior. i had absolutely no intention like this. i have actually tried out the suggestions posted. they actually did not work.



  • Try the below

    @
    QString name= ui->lineEdit_14->text();
    QString branch= ui->lineEdit_13->text();
    QString date= ui->lineEdit_15->text();
    QString cnct =ui->lineEdit_16->text();
    QString email= ui->lineEdit_17->text();
    QString addrss= ui->lineEdit_18->text();
    QString query = QString("INSERT INTO 'tab1' VALUES('%1','%2','%3','%4','%5','%6')").arg(name).arg(branch).arg(date).arg(cnct).arg(email).arg(addrss);
    q.exec( query );
    @

    I would strongly suggest you to go through the documentation for "QString":http://qt-project.org/doc/qt-4.8/QString.html. Infact you can click on the source code [highlighted with GREEN color] to go to the documentation page.



  • thank you sir. the code has worked. i was actually having a problem that i was trying to connect to the database using same connection that i have used ahead in my project. i had to change the connection also. now the code works fine.



  • Appreciate if you could edit the Topic and add [SOLVED] in the front to say that this thread is completed.



  • sure. i do it now



  • I always tried so very helpful


Log in to reply
 

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