hii there
the application contains three dialogs one of which contains QDataTable whose data comes from mysql.
the first dialog which is set as main widget under main is a login dialog after entering correct user name and password the second dialog is shown. this contains the QDataTable.
now i want that this QDataTable should get updated (i.e refresh itself) automatically without unloading and then loading itself whenever the database is changed.
the following is the code of main function below which is the code for the thread.
#include <qapplication.h>
#include <qstring.h>
#include <pthread.h>
#include <unistd.h>
#include <qdatatable.h>
#include <qsqldatabase.h>
#include <stdio.h>
#include <iostream.h>
void * thread2update(void *);
pthread_t dispthread1;
static int k=0;
int main ( int argc, char ** argv)
{
cout<<"main entered"<<endl;
db->setDatabaseName(“logindbâ€);
db->setUserName(“rootâ€);
db->setPassword(“â€);
db->setHostName(“localhost);
db->open();
loginfrm w;
a.setMainWidget(&w);
w.show();
cout<<"creating thread"<<endl;
pthread_create(&dispthread1,NULL,thread2update,NULL);
a.connect(&a, SIGNAL(lastWindowClosed(),&a,SLOT(quit()));
cout<<â€leaving mainâ€<<endl;
return a.exec();
}
void * thread2update(void *)
{
cout<<â€entering threadâ€<<endl;
while(g_end)
{
usleep(5000*1000);
update();
cout<<â€executed “<<k+1<<â€timesâ€<<endl;
k++;
};
cout<<â€leaving threadâ€<<endl;
}
#include <qapplication.h>
#include <qstring.h>
#include <pthread.h>
#include <unistd.h>
#include <qdatatable.h>
#include <qsqldatabase.h>
#include <stdio.h>
#include <iostream.h>
void * thread2update(void *);
pthread_t dispthread1;
static int k=0;
int main ( int argc, char ** argv)
{
QApplication a ( argc, argv);
cout<<"main entered"<<endl;
QSqlDatabase *db = QSqlDatabase::addDatabase(“ QMYSQL3â€);
db->setDatabaseName(“logindbâ€);
db->setUserName(“rootâ€);
db->setPassword(“â€);
db->setHostName(“localhost);
db->open();
loginfrm w;
a.setMainWidget(&w);
w.show();
cout<<"creating thread"<<endl;
pthread_create(&dispthread1,NULL,thread2update,NULL);
a.connect(&a, SIGNAL(lastWindowClosed(),&a,SLOT(quit()));
cout<<â€leaving mainâ€<<endl;
return a.exec();
}
void * thread2update(void *)
{
cout<<â€entering threadâ€<<endl;
while(g_end)
{
usleep(5000*1000);
update();
cout<<â€executed “<<k+1<<â€timesâ€<<endl;
k++;
};
cout<<â€leaving threadâ€<<endl;
}
To copy to clipboard, switch view to plain text mode
(please ignore any syntax or spelling errors coz this is not pasted code its hand written.)
g_end is a global variable and its value is changed in the second form on specific action.
when i compile this program it tell "update undeclared".
but in the code which i have got previously has this function to update the contents of the table. and when i comment that line of update() then it compiles well.
while running the program (with update commented) the output is something like this:
entering main
creating thread
leaving main
executed 1 times
executed 2 times
executed 3 times
and goes on till i end the program. this is the latest one and now it is not giving the error of segmentation fault.
but the problem is still not solved. i want that after login my QDataTable should get updated automatically. i.e. whenever any change is made in the database then it should display that change immediately.
tell me what function to use 4 this.
if u want i can mail the entire project folder. it is very small and has just three dialogs and three .ui.h files of code.
and finally let me clear to all that i had a bit confusion with kdevelop but now it is totally clear. afterall every newbie has it. but that doesnt mean that all should keep on saying that rather than concerntrating on the issue.
thanks and regards.
shamik
Bookmarks