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
相关推荐
小菜鸡桃蛋狗41 分钟前
C++——类和对象(下)
开发语言·c++
crescent_悦1 小时前
C++:Highest Price in Supply Chain
开发语言·c++
feng_you_ying_li1 小时前
底层实现map和set的第一步,AVL树的学习
c++
垫脚摸太阳1 小时前
第 36 场 蓝桥·算法挑战赛·百校联赛---赛后复盘
数据结构·c++·算法
Aaswk1 小时前
刷题笔记(回溯算法)
数据结构·c++·笔记·算法·leetcode·深度优先·剪枝
zhooyu1 小时前
GLM中lerp实现线性插值
c++·opengl
我不是懒洋洋2 小时前
预处理详解
c语言·开发语言·c++·windows·microsoft·青少年编程·visual studio
计算机安禾2 小时前
【数据结构与算法】第14篇:队列(一):循环队列(顺序存储
c语言·开发语言·数据结构·c++·算法·visual studio
IT从业者张某某2 小时前
基于EGE19.01完成恐龙跳跃游戏-V00-C++使用EGE19.01这个轮子
c++·游戏
-许平安-2 小时前
MCP项目笔记六(PluginsLoader)
c++·笔记·raii·plugin system