Solved work with input/output of Thread
-
Hi,
Before start thread pass that variable to some other method of thread class and store that variable in some member variable, after that start the thread in same method//in .h
QString uiData;//in thread class declare a method,
void uiData(Qstring str)
{
uiData = str;
this->start();
} -
@Alexanov Use signals/slots to exchange data
-
@jsulm
can you show me how can I exchange data with signal/ slot?(simple pseudo code is enough ) -
I guess I would do it, just as with the IODevice interfcae.
-
@Alexanov said in work with input/output of Thread:
I derive a class from QThread and implement the run() method Then use Thread->start() to run it.
If you don't have an event loop in that thread you can't have slots executed in it. Either move to the worker object approach or synchronize everything manually with mutexes.
-
-
@jsulm
I knew Signals and slots working algorithm and how use in my code. :)
My question is : How can send variables to main.cpp (GUI Thread Class) when emit Signal in my MyThread.cpp class ??and vice versa how can i send variable to MyThread.cpp with Signal/Slot? -
@kshegunov
you say for working with variable (send/receive) , is better to use worker object approach or synchronize everything manually with mutexes?In worker thread object can i send or receive between classes? (can you show me how ? with simple example?)
I need very easy solution to send or receive variable with thread ?(in C# language it was very easy but i did not know why in Qt in c language is very complex :( -
@Alexanov said in work with input/output of Thread:
you say for working with variable (send/receive) , is better to use worker object approach or synchronize everything manually with mutexes?
I didn't say any one is better, I just presented you with your two options. To have slots executed in a thread it has to have an event loop, which means you need to use a worker object. The other way to do it is to make your class(es) thread safe by manually synchronizing the concurrent access to the variables that are shared - through mutexes and/or semaphores.
In worker thread object can i send or receive between classes?
Yes, with signals and slots. All the examples you need are in the documentation and here in the forum, please search for them.
I need very easy solution to send or receive variable with thread ?(in C# language it was very easy but i did not know why in Qt in c language is very complex :(
There's no "very easy" when one talks about threading (and parallelism in general), there are no real "quick fixes", sorry. I don't know C# so I don't have any idea how easy it is, but C++ is a complex language with many, many, many pitfalls and nuances. Qt has nothing to do with it all, it's just a library that provides great convenience, but it will not do the work for you.
-
@kshegunov said in work with input/output of Thread:
examples
Thank you very much .....
I worked with signal /slot to transfer data between thread .