I want to create a qt application in which a function is called every 10 seconds to change the text in a qlineedit. I'm a newbie to qt programming. Please help me.
You want to use QTimer and connect it to a slot that does the update.
This class will do it (note, I typed this directly into StackOverflow, so there are probably compilation errors):
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());
}
You will need to modify it to do whatever you need.
Look at QTimer class. //or tell us more about what exactly you don't know how to do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.