PDA

View Full Version : local variables in QThread - derived class



TorAn
4th September 2016, 21:37
My current understanding is that variables that are created in the constructor of the QThread-derived class will nevertheless be created in the context of the thread that created the instance of such class. For example, in the case below variable "a" is created in the context of main thread, but variable "b" is created in the context of the thread "threadOne". Is my understanding correct?


class threadOne : public QThread
{
QString* a;
QString* b;
public:
threadOne() {
a = new QString();
}
private:
void run() {
b = new QString();
}
}

void main() {
threadOne thread;
}

anda_skoa
4th September 2016, 23:50
Yes, as the constructor is run by the thread that creates the threadOne object but run() is being executed on the new thread.

Cheers,
_