综合商城网站程序,精品课程网站开发平台,珍珠设计制作培训,最好的wordpress博客主题目录
public/slot function
signals
static public function
使用 public/slot function // 构造函数
// 如果指定了父对象, 创建的堆内存可以自动析构
QTimer::QTimer(QObject *parent nullptr);// 设置定时器时间间隔为 msec 毫秒
// 默认值是0#xff0c;一旦窗口系统…目录
public/slot function
signals
static public function
使用 public/slot function // 构造函数
// 如果指定了父对象, 创建的堆内存可以自动析构
QTimer::QTimer(QObject *parent nullptr);// 设置定时器时间间隔为 msec 毫秒
// 默认值是0一旦窗口系统事件队列中的所有事件都已经被处理完一个时间间隔为0的QTimer就会触发
void QTimer::setInterval(int msec);
// 获取定时器的时间间隔, 返回值单位: 毫秒
int QTimer::interval() const;// 根据指定的时间间隔启动或者重启定时器, 需要调用 setInterval() 设置时间间隔
[slot] void QTimer::start();
// 启动或重新启动定时器超时间隔为msec毫秒。
[slot] void QTimer::start(int msec);
// 停止定时器。
[slot] void QTimer::stop();// 设置定时器精度
/*
参数: - Qt::PreciseTimer - 精确的精度, 毫秒级- Qt::CoarseTimer - 粗糙的精度, 和1毫秒的误差在5%的范围内, 默认精度- Qt::VeryCoarseTimer - 非常粗糙的精度, 精度在1秒左右
*/
void QTimer::setTimerType(Qt::TimerType atype);
Qt::TimerType QTimer::timerType() const; // 获取当前定时器的精度// 如果定时器正在运行返回true; 否则返回false。
bool QTimer::isActive() const;// 判断定时器是否只触发一次
bool QTimer::isSingleShot() const;
// 设置定时器是否只触发一次, 参数为true定时器只触发一次, 为false定时器重复触发, 默认为false
void QTimer::setSingleShot(bool singleShot); 先创建对象然后设置定时器时间间隔然后运行然后接收发送的信号槽函数处理。 signals [signal] void QTimer::timeout(); static public function 功能: 在msec毫秒后发射一次信号, 并且只发射一次
参数:- msec: 在msec毫秒后发射信号- receiver: 接收信号的对象地址- method: 槽函数地址
*/
[static] void QTimer::singleShot(int msec, const QObject *receiver, PointerToMemberFunction method); 使用 // 创建定时器对象
QTimer* timer new QTimer(this);// 修改定时器对象的精度
timer-setTimerType(Qt::PreciseTimer);// 按钮 loopBtn 的点击事件
// 点击按钮启动或者关闭定时器, 定时器启动, 周期性得到当前时间
connect(ui-loopBtn, QPushButton::clicked, this, []()
{// 启动定时器if(timer-isActive()){timer-stop(); // 关闭定时器ui-loopBtn-setText(开始);}else{ui-loopBtn-setText(关闭);timer-start(1000); // 1000ms 1s}
});connect(timer, QTimer::timeout, this, []()
{QTime tm QTime::currentTime();// 格式化当前得到的系统时间QString tmstr tm.toString(hh:mm:ss.zzz);// 设置要显示的时间ui-curTime-setText(tmstr);
});// 点击按钮 onceBtn 只发射一次信号
// 点击按钮一次, 发射一个信号, 得到某一个时间点的时间
connect(ui-onceBtn, QPushButton::clicked, this, []()
{// 获取2s以后的系统时间, 不创建定时器对象, 直接使用类的静态方法QTimer::singleShot(2000, this, [](){QTime tm QTime::currentTime();// 格式化当前得到的系统时间QString tmstr tm.toString(hh:mm:ss.zzz);// 设置要显示的时间ui-onceTime-setText(tmstr);});
});