資源簡介
Qt 多線程及簡單實例 demo。
多線程的幾大特點:
1.多線程的執(zhí)行順序無法保證,與操作系統(tǒng)的調度策略和線程優(yōu)先級等因素有關。
2.多線程的切換可能發(fā)生在任何時刻、任何地點。
3.多線程對代碼的敏感度高,因此對代碼的細微修改都可能產(chǎn)生意想不到的效果。
先由一個簡單的例子引出多線程
先作出這個簡單的界面
“開始”對應的槽函數(shù)是:slotStart()
“停止”對應的槽函數(shù)是:slotStop()
本例中的線程(workthread類)實現(xiàn)的功能是,從0到9循環(huán)打印,0至9各占一排。
則該線程的具體實現(xiàn)詳見demo。
demo環(huán)境為qt5.9 64位

代碼片段和文件信息
/****************************************************************************
**?meta?object?code?from?reading?C++?file?‘widget.h‘
**
**?Created?by:?The?Qt?meta?object?Compiler?version?67?(Qt?5.9.0)
**
**?WARNING!?All?changes?made?in?this?file?will?be?lost!
*****************************************************************************/
#include?“../../threadSecond/widget.h“
#include?
#include?tatype.h>
#if?!defined(Q_MOC_OUTPUT_REVISION)
#error?“The?header?file?‘widget.h‘?doesn‘t?include?ject>.“
#elif?Q_MOC_OUTPUT_REVISION?!=?67
#error?“This?file?was?generated?using?the?moc?from?5.9.0.?It“
#error?“cannot?be?used?with?the?include?files?from?this?version?of?Qt.“
#error?“(The?moc?has?changed?too?much.)“
#endif
QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct?qt_meta_stringdata_Widget_t?{
????QByteArrayData?data[4];
????char?stringdata0[27];
};
#define?QT_MOC_LITERAL(idx?ofs?len)?\
????Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len?\
????qptrdiff(offsetof(qt_meta_stringdata_Widget_t?stringdata0)?+?ofs?\
????????-?idx?*?sizeof(QByteArrayData))?\
????)
static?const?qt_meta_stringdata_Widget_t?qt_meta_stringdata_Widget?=?{
????{
QT_MOC_LITERAL(0?0?6)?//?“Widget“
QT_MOC_LITERAL(1?7?9)?//?“slotStart“
QT_MOC_LITERAL(2?17?0)?//?““
QT_MOC_LITERAL(3?18?8)?//?“slotStop“
????}
????“Widget\0slotStart\0\0slotStop“
};
#undef?QT_MOC_LITERAL
static?const?uint?qt_meta_data_Widget[]?=?{
?//?content:
???????7???????//?revision
???????0???????//?classname
???????0????0?//?classinfo
???????2???14?//?methods
???????0????0?//?properties
???????0????0?//?enums/sets
???????0????0?//?constructors
???????0???????//?flags
???????0???????//?signalCount
?//?slots:?name?argc?parameters?tag?flags
???????1????0???24????2?0x08?/*?Private?*/
???????3????0???25????2?0x08?/*?Private?*/
?//?slots:?parameters
????QmetaType::Void
????QmetaType::Void
???????0????????//?eod
};
void?Widget::qt_static_metacall(Qobject?*_o?Qmetaobject::Call?_c?int?_id?void?**_a)
{
????if?(_c?==?Qmetaobject::InvokemetaMethod)?{
????????Widget?*_t?=?static_cast(_o);
????????Q_UNUSED(_t)
????????switch?(_id)?{
????????case?0:?_t->slotStart();?break;
????????case?1:?_t->slotStop();?break;
????????default:?;
????????}
????}
????Q_UNUSED(_a);
}
const?Qmetaobject?Widget::staticmetaobject?=?{
????{?&QWidget::staticmetaobject?qt_meta_stringdata_Widget.data
??????qt_meta_data_Widget??qt_static_metacall?nullptr?nullptr}
};
const?Qmetaobject?*Widget::metaobject()?const
{
????return?Qobject::d_ptr->metaobject???Qobject::d_ptr->dynamicmetaobject()?:?&staticmetaobject;
}
void?*Widget::qt_metacast(const?char?*_clname)
{
????if?(!_clname)?return?nullptr;
????if?(!strcmp(_clname?qt_meta_stringdata_Widget.stringdata0))
????????return?static_cast(const_cast(this));
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1216??2019-03-07?16:29??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\.qmake.stash
?????文件??????66072??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\main.obj
?????文件????????250??2019-03-07?16:30??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\moc_predefs.h
?????文件???????3566??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\moc_widget.cpp
?????文件??????59200??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\moc_widget.obj
?????文件???????2738??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\moc_WorkThread.cpp
?????文件??????49171??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\moc_WorkThread.obj
?????文件??????76800??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\threadSecond.exe
?????文件?????896904??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\threadSecond.ilk
?????文件????2166784??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\threadSecond.pdb
?????文件????1552384??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\threadSecond.vc.pdb
?????文件?????138775??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\widget.obj
?????文件??????63100??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug\WorkThread.obj
?????文件??????30627??2019-03-07?17:01??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\Makefile
?????文件??????51805??2019-03-07?17:01??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\Makefile.Debug
?????文件??????51829??2019-03-07?17:01??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\Makefile.Release
?????文件???????2439??2019-03-07?16:44??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\ui_widget.h
?????文件????????175??2019-03-07?16:29??threadSecond\threadSecond\main.cpp
?????文件???????1087??2019-03-07?16:46??threadSecond\threadSecond\threadSecond.pro
?????文件??????24004??2019-03-07?16:30??threadSecond\threadSecond\threadSecond.pro.user
?????文件????????970??2019-03-07?16:55??threadSecond\threadSecond\widget.cpp
?????文件????????403??2019-03-07?16:56??threadSecond\threadSecond\widget.h
?????文件???????1542??2019-03-07?16:43??threadSecond\threadSecond\widget.ui
?????文件????????244??2019-03-07?16:49??threadSecond\threadSecond\WorkThread.cpp
?????文件????????226??2019-03-07?17:13??threadSecond\threadSecond\WorkThread.h
?????目錄??????????0??2019-03-07?17:13??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\debug
?????目錄??????????0??2019-03-07?16:29??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug\release
?????目錄??????????0??2019-03-07?16:30??threadSecond\build-threadSecond-Desktop_Qt_5_9_0_MSVC2015_64bit-Debug
?????目錄??????????0??2019-03-07?17:13??threadSecond\threadSecond
?????目錄??????????0??2019-03-07?16:29??threadSecond
............此處省略3個文件信息
評論
共有 條評論