Re: Threads - General issue!
you can not directly acces the gui elements in seperate thread...
but you can use singals and slots that will update the gui... in other words... in your thread class make a signal like
void addTextToTable(QString text);
and then emit it whenever you want to change the text in gui...
in the main gui thread... create a slot and connect it to the above signal..
thats it.
Re: Threads - General issue!
Thank you MrDeath, that was exactly some guidance i was searching for. I will try it now and post back the results. :)
Re: Threads - General issue!
Take a look at the Queued Custom Type example. It will show you how can you create a worker thread and send custom data to the GUI using signals/slots across threads.
Re: Threads - General issue!
Queued Custom Type Example was of much help. :) thanks a lot victor.
Now I am stuck with another issue, and I think its again a silly one. Still gotta find a solution!
Here is my code:
master.cpp
Code:
thread = new RenderThread();
connect(ui.updateStatsButton, SIGNAL(clicked()), this, SLOT(updateStats()));
....
//in updateStats()
thread->startOffThread(sessionName, logPos, event_id);
thread.cpp
Code:
void RenderThread
::startOffThread(const QString &str,
int logPos, Event_Id event_id
) {
...
//some manipulations on variables supplied
start();
}
//in RenderThread::run()
do {
...
emit sendString(str, str2);
sleep(1);
}while (some_condition);
Now here is my problem - I have multiple Events on which the above actions have to be performed independently.
suppose i have Event01 and Event02. I clicked updateStats button for Event01 and code is executed properly and stats are being updated. Meanwhile I clicked updateStats for Event02 (where in functioncall
Code:
thread->startOffThread(sessionName, logPos, event_id);
the variables supplied differ) Event01 updation stops and Event02 starts!
:(
I want Event01 and Event02 (and many many more) to run parallelly without affecting each other.
How do I implement multiple threads?
How do start and stop them? I could not find anything similar to thread_id from pthreads.
someone please help...
Re: Threads - General issue!