[英]Changing text in qlineedit of qt application in real time
我想创建一个qt应用程序,其中每隔10秒调用一个函数来更改qlineedit中的文本。 我是qt编程的新手。 请帮我。
您想使用QTimer并将其连接到执行更新的插槽。
这个类会这样做(注意,我直接将它键入StackOverflow,因此可能存在编译错误):
class TextUpdater : public QObject {
public:
TextUpdater(QLineEdit* lineEdit);
public slots:
void updateText();
};
TextUpdater::TextUpdater(QLineEdit* edit)
:QObject(lineEdit), lineEdit(edit)
// make the line edit the parent so we'll get destroyed
// when the line edit is destroyed
{
QTimer* timer = new QTimer(this);
timer->setSingleShot(false);
timer->setInterval(10 * 1000); // 10 seconds
connect(timer, SIGNAL(timeout()), this, SLOT(updateText()));
}
void TextUpdater::updateText()
{
// Set the text to whatever you want. This is just to show it updating
lineEdit->setText(QTime::currentTime().toString());
}
您需要修改它以执行您需要的任何操作。
看看QTimer课程。 //或者告诉我们更多关于你究竟不知道怎么做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.