Skip to content

Commit

Permalink
重写多线程例子
Browse files Browse the repository at this point in the history
  • Loading branch information
RealChuan committed Nov 10, 2022
1 parent 29b761e commit 608092e
Show file tree
Hide file tree
Showing 43 changed files with 267 additions and 495 deletions.
2 changes: 1 addition & 1 deletion Battery/Battery.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion BubbleWindow/BubbleWindow.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Widgets Charts Network Concurrent Sql)
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Charts Network Concurrent Sql)

add_subdirectory(Battery)
add_subdirectory(BubbleWindow)
Expand Down
2 changes: 1 addition & 1 deletion Chart/Chart.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui charts

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion Clock/Clock.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion DashBoard/DashBoard.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion DragDrop/DragDrop.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion FlowLayout/FlowLayout.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
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.
Expand Down
2 changes: 1 addition & 1 deletion GridViewModel/GridViewModel.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
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.
Expand Down
2 changes: 1 addition & 1 deletion HttpClient/HttpClient.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui network concurrent

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion LogAsynchronous/LogAsynchronous.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui concurrent

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion MulClient/MulClient.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion MulServer/MulServer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion NavigationProgressBar/NavigationProgressBar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion ProgressArc/ProgressArc.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion ProgressBar/ProgressBar.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
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.
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@

<div align=center><img src="TableViewModel/picture/TabViewModelDelegate.png"></div>

## 23. [Thread](Thread/)——多线程例子,四种写法,控件更新在子线程;

<div align=center><img src="Thread/picture/Thread.png"></div>
## 23. [Thread](Thread/)——多线程例子,6种写法;

## 24. [TreeViewModel](TreeViewModel/)——树形视图(MVC),QtCreator源码;

Expand Down
2 changes: 1 addition & 1 deletion ReactorServer/ReactorServer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion SimpleUdp/SimpleUdp.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
QT -= gui
QT += network

CONFIG += c++11 console
CONFIG += c++17 console
CONFIG -= app_bundle

# You can make your code fail to compile if it uses deprecated APIs.
Expand Down
2 changes: 1 addition & 1 deletion SlipButton/SlipButton.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion SqlTabview/SqlTabview.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
2 changes: 1 addition & 1 deletion TableViewModel/TableViewModel.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11
CONFIG += c++17

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
Expand Down
22 changes: 9 additions & 13 deletions Thread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
set(PROJECT_SOURCES
main.cpp
mainwindow.cpp
mainwindow.h
test.h
test.cpp
thread1.h
thread1.cpp
thread2.h
thread2.cpp
thread3.h
thread3.cpp)
functions.cc
functions.hpp
main.cc
task.cc
task.hpp
thread.cc
thread.hpp)

qt_add_executable(Thread MANUAL_FINALIZATION ${PROJECT_SOURCES})
target_link_libraries(Thread PRIVATE Qt6::Widgets Qt6::Concurrent)
qt_finalize_executable(Thread)
target_link_libraries(Thread PRIVATE Qt6::Core Qt6::Concurrent)
qt_finalize_executable(Thread)
38 changes: 14 additions & 24 deletions Thread/Thread.pro
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
QT += core gui concurrent
QT -= gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += concurrent

CONFIG += c++11
CONFIG += c++17 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
mainwindow.cpp \
test.cpp \
thread1.cpp \
thread2.cpp \
thread3.cpp

HEADERS += \
mainwindow.h \
test.h \
thread1.h \
thread2.h \
thread3.h
functions.cc \
main.cc \
task.cc \
thread.cc

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

HEADERS += \
functions.hpp \
task.hpp \
thread.hpp
9 changes: 9 additions & 0 deletions Thread/functions.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "functions.hpp"

#include <QThread>

QString Functions::getCurrentThreadIDStr()
{
return QString("Current Thread ID: %1.")
.arg(reinterpret_cast<qint64>(QThread::currentThreadId()));
}
12 changes: 12 additions & 0 deletions Thread/functions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef FUNCTIONS_HPP
#define FUNCTIONS_HPP

#include <QtCore/qglobal.h>

namespace Functions {

QString getCurrentThreadIDStr();

}

#endif // FUNCTIONS_HPP
30 changes: 30 additions & 0 deletions Thread/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <QTimer>
#include <QtCore/QCoreApplication>

#include "thread.hpp"

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QScopedPointer<Thread1> t1(new Thread1);
t1->start();

QScopedPointer<Thread2> t2(new Thread2);
t2->start();
QObject::connect(t2.data(), &Thread2::started, t2.data(), &Thread2::onDo);

QScopedPointer<Thread3> t3(new Thread3);
t3->dooo();

runThread4();

runThread5();

QScopedPointer<QThread> t6(runThread6());
t6->start();

QTimer::singleShot(1000, &a, &QCoreApplication::quit);

return a.exec();
}
11 changes: 0 additions & 11 deletions Thread/main.cpp

This file was deleted.

Loading

0 comments on commit 608092e

Please sign in to comment.