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. [Solved] Closing a dialog with a timer.
Forum Updated to NodeBB v4.3 + New Features

[Solved] Closing a dialog with a timer.

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 12.3k Views 1 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.
  • G Offline
    G Offline
    guptaprashant1986gmail
    wrote on 16 Apr 2012, 12:47 last edited by
    #1

    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]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on 16 Apr 2012, 15:22 last edited by
      #2

      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.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guptaprashant1986gmail
        wrote on 16 Apr 2012, 17:36 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          veeraps
          wrote on 17 Apr 2012, 07:03 last edited by
          #4

          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?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guptaprashant1986gmail
            wrote on 17 Apr 2012, 14:15 last edited by
            #5

            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
            1 Reply Last reply
            0
            • V Offline
              V Offline
              veeraps
              wrote on 18 Apr 2012, 05:38 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                guptaprashant1986gmail
                wrote on 18 Apr 2012, 15:02 last edited by
                #7

                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]

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on 18 Apr 2012, 15:34 last edited by
                  #8

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

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    guptaprashant1986gmail
                    wrote on 18 Apr 2012, 15:40 last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on 18 Apr 2012, 15:43 last edited by
                      #10

                      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.

                      Software Engineer
                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        guptaprashant1986gmail
                        wrote on 18 Apr 2012, 16:57 last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • V Offline
                          V Offline
                          veeraps
                          wrote on 19 Apr 2012, 01:10 last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            guptaprashant1986gmail
                            wrote on 19 Apr 2012, 05:05 last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              veeraps
                              wrote on 19 Apr 2012, 05:19 last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                guptaprashant1986gmail
                                wrote on 19 Apr 2012, 05:21 last edited by
                                #15

                                sure. i do it now

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  gdouglas7
                                  wrote on 20 Apr 2012, 15:45 last edited by
                                  #16

                                  I always tried so very helpful

                                  Qt Developer
                                  Student of Information System

                                  1 Reply Last reply
                                  0

                                  4/16

                                  17 Apr 2012, 07:03

                                  topic:navigator.unread, 12
                                  • Login

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