Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, July 2007
Fwd: qtimer problem in multiprocessing environment


Message 1 in thread


Note: forwarded message attached.

- Navneet Kataria
 
 




       
---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. 
--- Begin Message ---
Hello All,

I am facing a problem while working with qtimers. 

I had made a dialog for editing system date-time. Also I wanted to have a auto time-out feature for the dialog box. It means if no keyboard/mouse event on the dialog box, then it should close with-in 2 mintues. So i have started a timer with a timeout of 120 seconds when i show the dialog box to the user. When-ever the user moves mouse/uses keyboard, the event are detects and i reset the timer with sop and start call.
Every thing is working fine expect when-ever i change the system date/time back-wards, then timer times-out almost immediately instead of waiting for 120 seconds.
I am attaching the source code(three files only) with the mail. Can any-body help ?

p.s. :: I am using qt version 3.3.6 on gnu/linux operating system.


- Navneet Kataria
 
 




       
---------------------------------
Building a website is a piece of cake. 
Yahoo! Small Business gives you all the tools to get online.

Attachment: main.cpp
Description: 3236398785-main.cpp

Attachment: dateTimeEdit.cpp
Description: 901295746-dateTimeEdit.cpp

Attachment: dateTimeEdit.h
Description: 891380842-dateTimeEdit.h


--- End Message ---

Message 2 in thread

Hello All,

I am facing a problem while working with qtimers. 

I had made a dialog for editing system date-time. Also I wanted to have a auto time-out feature for the dialog box. It means if no keyboard/mouse event on the dialog box, then it should close with-in 2 mintues. So i have started a timer with a timeout of 120 seconds when i show the dialog box to the user. When-ever the user moves mouse/uses keyboard, the event are detects and i reset the timer with stop and start call.
Every thing is working fine expect when-ever i change the system date/time back-wards, then timer times-out almost immediately instead of waiting for 120 seconds.
Below is the code. Can any-body help ?

p.s. :: I am using qt version 3.3.6 on gnu/linux operating system.
####################################
-------------------------------------------
main.cpp
------------------------------------------
#include <iostream>
#include <qapplication.h>

#include "dateTimeEdit.h"

int main(int argc,char* argv[])
{
    QApplication qapp(argc,argv);
    DateTimeEditDialog *dt = new DateTimeEditDialog();
    dt->show();
    qapp.setMainWidget(dt);
    return qapp.exec();
}
#################################
---------------------------------------------
dateTimeEdit.h
---------------------------------------------
#ifndef DATETIMEEDIT_H
#define DATETIMEEDIT_H
#include <qdialog.h>
#include <qtimer.h>
#define TIMEOUT 120000

class QLabel;
class QPushButton;
class QDateTimeEdit;

class DateTimeEditDialog : public QDialog
{
    Q_OBJECT
public:
    DateTimeEditDialog( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~DateTimeEditDialog();

    QLabel* textLabel1;
    QPushButton* okButton;
    QPushButton* cancelButton;
    QLabel* textLabel2;
    QLabel* formatLabel;
    QDateTimeEdit* dateTimeEdit1;
    QDateTimeEdit* dateTimeEdit2;
    QTimer *formTimer;

protected:
    bool event(QEvent*);

protected slots:
    virtual void languageChange();
    virtual void okClicked();
    virtual void cancelClicked();

};
#endif // DATETIMEEDIT_H
-----------------------------
##########################################
-----------------------------------------------------
dateTimeEdit.cpp
-----------------------------------------------------
#include <iostream>
#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qdatetimeedit.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qmessagebox.h>

#include "dateTimeEdit.h"

DateTimeEditDialog::DateTimeEditDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )
{
    if ( !name )
    setName( "DateTimeEditDialog" );

    this->setWFlags(Qt::WDestructiveClose);

    textLabel1 = new QLabel( this, "textLabel1" );
    textLabel1->setGeometry( QRect( 20, 80, 180, 30 ) );
     okButton = new QPushButton( this, "okButton" );
    okButton->setGeometry( QRect( 120, 130, 86, 28 ) );

    cancelButton = new QPushButton( this, "cancelButton" );
    cancelButton->setGeometry( QRect( 230, 130, 86, 28 ) );

    textLabel2 = new QLabel( this, "textLabel2" );
    textLabel2->setGeometry( QRect( 20, 30, 180, 30 ) );

    formatLabel = new QLabel( this, "formatLabel" );
    formatLabel->setGeometry( QRect( 200, 0, 201, 21 ) );

    QDate minDate(2000,1,1);
    QDate maxDate(2037,1,1);
    dateTimeEdit1 = new QDateTimeEdit( this, "dateTimeEdit1" );
    dateTimeEdit1->setGeometry( QRect( 200, 80, 232, 33 ) );
    dateTimeEdit1->dateEdit()->setOrder(QDateEdit::DMY);
    dateTimeEdit1->setDateTime(QDateTime::currentDateTime());
    dateTimeEdit1->dateEdit()->setRange(minDate,maxDate);

    dateTimeEdit2 = new QDateTimeEdit( this, "dateTimeEdit2" );
    dateTimeEdit2->setEnabled( FALSE );
    dateTimeEdit2->setGeometry( QRect( 200, 30, 232, 33 ) );
    dateTimeEdit2->dateEdit()->setOrder(QDateEdit::DMY);
    dateTimeEdit2->setPaletteBackgroundColor( QColor( 85, 0, 0 ) );
    dateTimeEdit2->setDateTime( QDateTime::currentDateTime() );

    formTimer = new QTimer(this,"formTimer");
    connect(formTimer,SIGNAL(timeout()),this,SLOT(close()));
    this->setMouseTracking(true);

    languageChange();
    resize( QSize(458, 210).expandedTo(minimumSizeHint()) );
    clearWState( WState_Polished );
}

DateTimeEditDialog::~DateTimeEditDialog()
{
    // no need to delete child widgets, Qt does it all for us
}

void DateTimeEditDialog::languageChange()
{
    setCaption( tr( "Change Date/Time" ) );
    textLabel1->setText( tr( "Change Date/Time" ) );
    okButton->setText( tr( "Change" ) );
    cancelButton->setText( tr( "Close" ) );
    textLabel2->setText( tr( "Current Date/Time" ) );
    formatLabel->setText( tr( " dd/mm/yyyy              hh:mm:ss" ) );

    connect(okButton,SIGNAL(clicked()),this,SLOT(okClicked()));
    connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancelClicked()));
}

bool DateTimeEditDialog::event(QEvent* e)
{
    formTimer->stop();
    formTimer->start(TIMEOUT,TRUE);
    return QDialog::event(e);
}
void DateTimeEditDialog::okClicked()
{
    QString comm="";
    comm = QString("date ") + ((dateTimeEdit1->dateTime()).toString("MMddhhmmyyyy.ss"));

    if(system(comm.latin1()) == 0) {
        QMessageBox *msgBox = new QMessageBox("Change Date/Time","System Date-Time Changed",QMessageBox::Information,1,0,0,this,"msgBox",true,Qt::WDestructiveClose);
        msgBox->show();
        dateTimeEdit2->setDateTime( QDateTime::currentDateTime() );     // Resetting current date-time text box
    } else {
        QMessageBox *msgBox = new QMessageBox("Change Date/Time","Unable to change System Date-Time",QMessageBox::Information,1,0,0,this,"msgBox",true,Qt::WDestructiveClose);
        msgBox->show();
    }

}

void DateTimeEditDialog::cancelClicked()
{
    reject();
}
----------------------------------------------------------------------------

   - Navneet Kataria


- Navneet Kataria
 
 




       
---------------------------------
Park yourself in front of a world of choices in alternative vehicles.
Visit the Yahoo! Auto Green Center.