[英]How to use a variable from a slot in another slot in QT
I am learning QT and have this problem. 我正在学习QT并遇到此问题。 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? 如何在此代码中访问
var_slot1
的值?
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;
}
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.
然后,您将可以从两个成员函数中访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.