Programming/qt
Qtimer를 이용한 반복/1회성 이벤트 생성
구차니
2026. 3. 30. 11:30
결국은 슬롯에다가 시그널 보내는데
Qtimer::singleShot() 이 있어서 단회성으로 발생이 가능한 듯.
| //QTimer::singleShot(30000, ui->lbl_welcome,&QLabel::hide); QTimer::singleShot(30000,ui->lbl_welcome,SLOT(hide())); |
[링크 : https://forum.qt.io/topic/65799/how-to-display-label-for-30-seconds-and-then-hide-it/5]
[링크 : https://dev-astra.tistory.com/432]
[링크 : https://dongyeop00.tistory.com/86]
| void QTimer::start(std::chrono::milliseconds interval) Starts or restarts the timer with a timeout of duration interval milliseconds. This is equivalent to: timer.setInterval(interval); timer.start(); If the timer is already running, it will be stopped and restarted. This will also change its id(). If singleShot is true, the timer will be activated only once. Starting from Qt 6.10, setting a negative interval will result in a run-time warning and the value being reset to 1ms. Before Qt 6.10 a Qt Timer would let you set a negative interval but behave in surprising ways (for example stop the timer if it was running or not start it at all). |
[링크 : https://doc.qt.io/qt-6/qtimer.html#start-2]
| template <typename Duration, typename Functor> void QTimer::singleShot(Duration interval, const QObject *context, Functor &&functor) [static]template <typename Duration, typename Functor> void QTimer::singleShot(Duration interval, Qt::TimerType timerType, const QObject *context, Functor &&functor) [static]template <typename Duration, typename Functor> void QTimer::singleShot(Duration interval, Functor &&functor) [static]template <typename Duration, typename Functor> void QTimer::singleShot(Duration interval, Qt::TimerType timerType, Functor &&functor) This static function calls functor after interval. It is very convenient to use this function because you do not need to bother with a timerEvent or create a local QTimer object. If context is specified, then the functor will be called only if the context object has not been destroyed before the interval occurs. The functor will then be run the thread of context. The context's thread must have a running Qt event loop. If functor is a member function of context, then the function will be called on the object. The interval parameter can be an int (interpreted as a millisecond count) or a std::chrono type that implicitly converts to nanoseconds. Starting from Qt 6.10, setting a negative interval will result in a run-time warning and the value being reset to 1ms. Before Qt 6.10 a Qt Timer would let you set a negative interval but behave in surprising ways (for example stop the timer if it was running or not start it at all). |