[英]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.