Reputation: 638
I am learning QT and have this problem. I have read some nearly similar questions here but the solutions are complicated to a newbie like me.
How can I access the value of var_slot1
in this code?
Please help me to solve this. Many thanks !
MyProject::MyProject(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
..........
..........
connect(ui.button1, SIGNAL(signal1()), this, SLOT(slot1()));
connect(ui.button2, SIGNAL(signal2()), this, SLOT(slot2()));
}
void MyProject::slot1()
{
int var_slot1 = 8;
}
void MyProject::slot2()
{
int var_slot2 = var_slot1 + 2;
}
Upvotes: 0
Views: 116
Reputation: 31447
You can save the value as a class member variable rather than as a function-local variable. Then you'll be able to access it from both member functions.
Upvotes: 4