Hi guys im having kind of a headache understanding threads in Qt.
I`ve already read some post about QThread and the You are doing it blog entry but somehow I cant understand the full concep...
My idea is to show a loading widget while i load my application data. So far I ve the following code:
#include <QtGui/QApplication>
#include <QObject>
#include "waitthread.h"
#include "loadthread.h"
int main(int argc, char *argv[])
{
LoadThread * load_thread = new LoadThread ();
WaitThread * wait_thread = new WaitThread ();
QObject::connect (load_thread,
SIGNAL(load_finished
()), wait_thread,
SLOT(loading_finished
()));
load_thread->start ();
wait_thread->start ();
return a.exec ();
}
#include <QtGui/QApplication>
#include <QObject>
#include "waitthread.h"
#include "loadthread.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setStyle (new IconSize ());
LoadThread * load_thread = new LoadThread ();
WaitThread * wait_thread = new WaitThread ();
QObject::connect (load_thread, SIGNAL(load_finished()), wait_thread, SLOT(loading_finished()));
load_thread->start ();
wait_thread->start ();
return a.exec ();
}
To copy to clipboard, switch view to plain text mode
the loadthread.cpp:
LoadThread::LoadThread()
{
mainWin = new MainWindow ();
}
void LoadThread::run (){
//--------------------do some stuff
emit load_finished ();
emit load_finished ();
show_mainWin ();
}
void LoadThread::show_mainWin (){
mainWin->show ();
}
LoadThread::LoadThread()
{
mainWin = new MainWindow ();
}
void LoadThread::run (){
//--------------------do some stuff
emit load_finished ();
emit load_finished ();
show_mainWin ();
}
void LoadThread::show_mainWin (){
mainWin->show ();
}
To copy to clipboard, switch view to plain text mode
And the waitThread.cpp
#include "waitthread.h"
WaitThread::WaitThread()
{
loadwidg = new LoadingWidget ();
loadwidg->show ();
}
void WaitThread::run (){
}
void WaitThread::loading_finished (){
loadwidg->close ();
delete loadwidg;
this->terminate ();
}
#include "waitthread.h"
WaitThread::WaitThread()
{
loadwidg = new LoadingWidget ();
loadwidg->show ();
}
void WaitThread::run (){
}
void WaitThread::loading_finished (){
loadwidg->close ();
delete loadwidg;
this->terminate ();
}
To copy to clipboard, switch view to plain text mode
I think that the signal is received because the loading widget is closed...but mainWin only pops up for a split sec, like the object Qthread is destroyed...I know that im designing this the wrong way...hope someone can give a hand to fully understand this...
Bookmarks