QT多线程

1.QT4.7以前的版本-----线程处理方式

1. 出现的警告

直接使用从UI--->转到槽,就会出现警告

2. 出现的错误

error: invalid operands of types 'QTimer*' and 'void (QTimer::*)(QTimer::QPrivateSignal)' to binary 'operator&'

错误:无效的操作数类型'QTimer*'和'void (QTimer:😗)(QTimer::QPrivateSignal)'到二进制'operator&'

忘记在函数参数中加入逗号

cpp 复制代码
connect(myTimer,&QTimer::timeout,this,&Widget::dealTimerout);

3.多线程编程

3.1创建线程类

4.多线程测试案例

.pro

cpp 复制代码
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

FORMS += \
    widget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

.widget.h

cpp 复制代码
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTimer>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();


    //定义定时器槽函数
    void dealTimerout();



private slots:


    void on_bthStart_clicked();

private:
    Ui::Widget *ui;
    QTimer *myTimer;//声明一个定时器变量

};
#endif // WIDGET_H
相关推荐
会编程的小孩5 分钟前
qt_day1
c++
INGNIGHT36 分钟前
377.组合总和 Ⅳ(背包)
c++·算法·1024程序员节
凉茶钱1 小时前
stack、queue、priority_queue、容器适配器完整梳理
开发语言·c++·queue·1024程序员节·stack
wuminyu1 小时前
JVM规范学习总结-Java源码经过javac编译后产物
java·linux·c语言·jvm·c++
蹊黎1 小时前
C++中stack、queue、priority queue类的部分简单实现
数据结构·c++·visualstudio·1024程序员节
攻城狮Soar2 小时前
详解volatile
开发语言·c++·1024程序员节
東隅已逝,桑榆非晚2 小时前
搜索二叉树
c++·笔记·学习·1024程序员节
hetao173383712 小时前
2026-10-22~23 hetao1733837 的刷题记录
c++·算法
王老师青少年编程13 小时前
2025年6月GESP真题及题解(C++三级): 选择题和判断题(题解)
c++·真题·gesp·答案·csp·三级·信奥赛
卡卡~~13 小时前
“101计划”核心课程实践教材《数据实验结构指导-C++语言版》题目集
开发语言·c++·学习·算法