QT 连接信号槽并在构造函数中初始化 [英] QT Connect Signal Slot and initialize in constructor
本文介绍了QT 连接信号槽并在构造函数中初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在构造函数中创建连接并初始化它们.但是连接不起作用(在方法内部).
I create connections between widged in the constructor and also initialize them. But the connect not working (inside the methode).
代码说明了很多:
MyApp::MyApp(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);
// slider to spinbox
connect(ui.slider, SIGNAL(valueChanged(int)), ui.spinbox, SLOT(setValue(int)));
// SIGNAL To SLOT not called
ui.slider->setValue(2);
// I have to set this also:
ui.spinbox->setValue(2);
}
推荐答案
你试过了吗
connect(ui.slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
并在滑块更改时让插槽 setValue(int) 更新旋转框?
and have the slot setValue(int) update the spinbox when the slider is changed?
如果需要双向连接,则需要建立两个连接.一个将信号/插槽连接到滑块,一个将信号/插槽连接到微调框.
If you need it to go both ways, you will need to make two connections. One to connect a signal/slot to the slider, and one to connect a signal/slot to the spinbox.
另外,您有任何错误吗?
Also, are you getting any errors?
这篇关于QT 连接信号槽并在构造函数中初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文