#include <QApplication>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QSlider>
#include <QSpinBox>
#include <QString>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("Enter Your Age");
QTextEdit *spinBox = new QTextEdit;
QTextEdit *slider = new QTextEdit;
QObject::connect(spinBox, SIGNAL(textChanged(const QString &)),
slider, SLOT(setText(const QString &)));
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
window->setLayout(layout);
window->show();
return app.exec();
}
为什么不能一个文本框变另一个文本框跟着变
跟着样例改的,看到变量名不要奇怪
qt
------解决方案--------------------
QObject::connect(spinBox, SIGNAL(textChanged(const QString &)), slider, SLOT(setText(const QString &)));
QObject::connect(slider, SIGNAL(textChanged(const QString &)), spinBox, SLOT(setText(const QString &)));
------解决方案--------------------
应该是connect无效吧,textChanged(const QString &)是Qt3才有的,Qt4是textChanged(),所以你应该用一个slot接收它再给另一个控件赋值即可。