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
相关推荐
Stanford_11063 小时前
如何利用Python进行数据分析与可视化的具体操作指南
开发语言·c++·python·微信小程序·微信公众平台·twitter·微信开放平台
千里马-horse4 小时前
Async++ 源码分析8--partitioner.h
开发语言·c++·async++·partitioner
Lucis__5 小时前
再探类&对象——C++入门进阶
开发语言·c++
北京不会遇到西雅图6 小时前
【SLAM】【后端优化】不同优化方法对比
c++·机器人
jndingxin6 小时前
c++多线程(6)------ 条件变量
开发语言·c++
程序员莫小特6 小时前
老题新解|大整数加法
数据结构·c++·算法
洲覆8 小时前
C++ 模板、泛型与 auto 关键字
开发语言·数据结构·c++
千里马-horse9 小时前
Async++ 源码分析7--parallel_reduce.h
开发语言·c++·async++·parallel_reduce
江公望9 小时前
Qt QThread使用方法入门浅解
c++·qt
叫我龙翔9 小时前
【MySQL】从零开始了解数据库开发 --- 数据表的约束
android·c++·mysql·数据库开发