PDA

View Full Version : How to access parents variables



revellix
10th October 2011, 14:19
Hi Folks,

I don't get it. I have a QWidget and a QThread(*parent). Now the QWidget starts the QThread(*parent). In this QThread I want to access the variables in the QWidget. Imagine the QWidget holds an iserinput like QLineEdit.

Finally I have two Headers:

#1.


#include ...

class UserInput : public QWidget
{
Q_OBJECT
public:
explicit UserInput(QWidget *parent = 0);

QLineEdit *inputLine;
}


#2

#include ...

class algorithmus : public QThread
{
Q_OBJECT
public:
explicit algorithmus(QWidget *parent)

Now in the Contructor of the QWidget


....

calc = new algorithmus(this);

Finally I want to access the QLineEdit in the QWidget for the calculation in QThread:



....

return this->parent()->inputLine.toInt() + 1000; //f.e.

Is this even possible?? I am a newbie :)

wysota
10th October 2011, 14:34
Ignoring completely the C++ aspect of the question, you can't access widgets from within threads.

revellix
10th October 2011, 15:02
ok... and is it possbile between two QWidgtes?

wysota
10th October 2011, 15:03
If you use proper C++ syntax and respect scopes then yes.