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 分钟前
(LeetCode 面试经典 150 题) 138. 随机链表的复制 (哈希表)
java·c++·leetcode·链表·面试·go
君鼎14 分钟前
Effective C++ 条款17:以独立语句将newed对象置入智能指针
c++
极客BIM工作室1 小时前
深入理解C++中的Lazy Evaluation:延迟计算的艺术
开发语言·c++
小指纹3 小时前
图论-最短路Dijkstra算法
数据结构·c++·算法·深度优先·图论
王德博客4 小时前
【从基础到实战】STL string 学习笔记(上)
c++·笔记·学习
Algebraaaaa4 小时前
C++ 中 NULL 与 nullptr 有什么区别?
开发语言·c++
源代码•宸7 小时前
深入浅出设计模式——创建型模式之建造者模式 Builder
c++·经验分享·设计模式·建造者模式
itgather8 小时前
智能图书馆管理系统开发实战系列(五):前后端集成 - koffi调用与接口设计
c++·koffi
爱吃KFC的大肥羊9 小时前
C/C++常用字符串函数
c语言·数据结构·c++·算法
岁忧10 小时前
(nice!!!)(LeetCode 每日一题) 2561. 重排水果 (哈希表 + 贪心)
java·c++·算法·leetcode·go·散列表