main.cpp is as under :
#include <qapplication.h>
#include "loginfrm.h"
#include "editfrm.h"
#include<qsqldatabase.h>
#include<qstring.h>
#include <qthread.h>
#include <stdlib.h>
#include <qwidget.h>
#include <qtimer.h>
int main( int argc, char **argv )
{
db->setDatabaseName("logindb");
db->setUserName("root");
db->setPassword("");
db->setHostName("localhost");
db->open();
if ( !db->open())
{
qWarning(" database connection no thayu ");
}
editfrm efrm;
a.setMainWidget( &efrm );
efrm.show();
qWarning("waiting for login");
qWarning("creating timer");
efrm.connect( timer, SIGNAL(timeout()), SLOT(refreshTable()) );
timer->start( 5000, FALSE ); /* 3 seconds single-shot timer 3000 */
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
qWarning("Leaving main");
return a.exec();
}
#include <qapplication.h>
#include "loginfrm.h"
#include "editfrm.h"
#include<qsqldatabase.h>
#include<qstring.h>
#include <qthread.h>
#include <stdlib.h>
#include <qwidget.h>
#include <qtimer.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QSqlDatabase *db = QSqlDatabase::addDatabase("QMYSQL3");
db->setDatabaseName("logindb");
db->setUserName("root");
db->setPassword("");
db->setHostName("localhost");
db->open();
if ( !db->open())
{
qWarning(" database connection no thayu ");
}
editfrm efrm;
a.setMainWidget( &efrm );
efrm.show();
qWarning("waiting for login");
qWarning("creating timer");
QTimer *timer = new QTimer( &efrm , "mt" );
efrm.connect( timer, SIGNAL(timeout()), SLOT(refreshTable()) );
timer->start( 5000, FALSE ); /* 3 seconds single-shot timer 3000 */
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
qWarning("Leaving main");
return a.exec();
}
To copy to clipboard, switch view to plain text mode
NOTE : the editfrm gets some of its values from loginfrm because it is loaded first. but for the ease of understanding i have directly called editfrm from the main. It might be incorrect from the implementation point of view but it is absolutely correct logically. The loginfrm does nothing but initializes some global variables so that editfrm can use it. In the actual code the loginfrm is loaded first and then if the login is correct then the editfrm is loaded. It is only here that i have changed main function to show() the editfrm directly.
editfrm.ui.h is as follows :
#include<qapplication.h>
#include<qsqldatabase.h>
#include "loginfrm.h"
#include "modifyfrm.h"
#include <qwidget.h>
#include<qdatatable.h>
#include <qtimer.h>
#include<qthread.h>
#include <qobject.h>
#include <qtable.h>
#include <qsqlcursor.h>
static int btn;
static int i=0;
void editfrm::initvalues()
{
loginfrm *lfrm = new loginfrm();
if ( lfrm->check())
{
PB_add->setEnabled(TRUE);
PB_edit->setEnabled(TRUE);
PB_delete->setEnabled(TRUE);
}
else
{
PB_add->setEnabled(FALSE);
PB_edit->setEnabled(FALSE);
PB_delete->setEnabled(FALSE);
}
}
void editfrm::addclicked()
{
btn=1;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
void editfrm::editclicked()
{
btn=2;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
void editfrm::deleteclicked()
{
btn=3;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
int editfrm::checkbtn()
{
return btn;
}
void editfrm::cancelclicked()
{
loginfrm *lfrm = new loginfrm(this);
hide();
lfrm->show();
}
void editfrm::refreshTable()
{
swar.sprintf("tick tick %d",i);
qWarning(swar);
dataTable1->update();
dataTable1->repaint(true);
dataTable1->refresh(QDataTable::RefreshAll);
update();
i++;
}
#include<qapplication.h>
#include<qsqldatabase.h>
#include "loginfrm.h"
#include "modifyfrm.h"
#include <qwidget.h>
#include<qdatatable.h>
#include <qtimer.h>
#include<qthread.h>
#include <qobject.h>
#include <qtable.h>
#include <qsqlcursor.h>
static int btn;
static int i=0;
void editfrm::initvalues()
{
loginfrm *lfrm = new loginfrm();
if ( lfrm->check())
{
PB_add->setEnabled(TRUE);
PB_edit->setEnabled(TRUE);
PB_delete->setEnabled(TRUE);
}
else
{
PB_add->setEnabled(FALSE);
PB_edit->setEnabled(FALSE);
PB_delete->setEnabled(FALSE);
}
}
void editfrm::addclicked()
{
btn=1;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
void editfrm::editclicked()
{
btn=2;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
void editfrm::deleteclicked()
{
btn=3;
modifyfrm *mfrm = new modifyfrm();
mfrm->initvalues();
hide();
mfrm->show();
}
int editfrm::checkbtn()
{
return btn;
}
void editfrm::cancelclicked()
{
loginfrm *lfrm = new loginfrm(this);
hide();
lfrm->show();
}
void editfrm::refreshTable()
{
QString swar="";
swar.sprintf("tick tick %d",i);
qWarning(swar);
dataTable1->update();
dataTable1->repaint(true);
dataTable1->refresh(QDataTable::RefreshAll);
update();
i++;
}
To copy to clipboard, switch view to plain text mode
as per the timer after every 3 secs "tick tick i " is printed but the datatable is not getting updated or refreshed.
as u can see i have tried out with update(), repaint(), refresh(), none of which is working here. the datatable is failing to show the updated database. The database is getting updated from another GUI which is out of this project. I simultaneously run both the project 's GUI and after making changes in the database from one GUI in one project it doesnt get showed in the GUI of another project.
i hope atleast now the picture is very much clear.
please help me solve this problem
thanks and regards
shamik
Bookmarks