Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
被 Qt 快樂的玩弄 part 1
Search
nctunba
May 30, 2012
Programming
320
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
被 Qt 快樂的玩弄 part 1
nctunba
May 30, 2012
More Decks by nctunba
See All by nctunba
被 Qt 快樂的玩弄
nctunba
2
420
Node - Express - Socket.io
nctunba
1
440
Python
nctunba
3
570
node
nctunba
9
50k
jQuery
nctunba
8
630
JS
nctunba
11
650
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
120
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
400
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
3k
JIS keyboard support in Omarchy
lef237
0
180
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
200
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Getting Started with Vibe Coding
miccheng
0
180
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
280
オーケストレーション記述言語 Katari
yukikurage
0
220
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
380
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
300
AI-Powered Domain-Driven Design
ziobrando
0
380
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
600
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
970
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
How to train your dragon (web standard)
notwaldorf
96
6.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
360
KATA
mclloyd
PRO
35
16k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
370
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
Transcript
打開您的 IE 瀏覽器 在網址列鍵入 http://google.com/chrome/eula.html?standalone=1 下載完成後,關閉您的 IE
瀏覽器 1 前置準備
被 Qt 快樂的玩弄 簡易視窗程式教學 2 作者:兩大類
我不是大師,只是廢物! Qt 太肥,而小弟太瘦,有錯請包涵。 3 不負責任宣告
4 Qt cute?
安裝 Qt(1/6) 5
安裝 Qt(2/6) 6
安裝 Qt(3/6) 7
安裝 Qt(4/6) 8
安裝 Qt(5/6) 9 Development Tools • Desktop Qt • Qt
4.8.0 (Desktop) • Desktop Qt 4.8 – MinGW Miscellaneous • MinGW 4.4 Documentation • Qt Documentation
安裝 Qt(6/6) 10 搞定!
推薦閱讀(1/3) 11 C++ GUI Programming with Qt 4, 2/e Jasmin
Blanchette, Mark Summerfield
推薦閱讀(2/3) 12 Foundations of Qt Development Johan Thelin
推薦閱讀(3/3) 13 官方網站,綻放光芒。
2. 往右走進入 NBA 社窩,搜尋左側書櫃 3. 將心儀的對象拿起,坐在地上開始閱讀 1. 打開教室的門。 沒有錢怎麼辦? 14
C++ 的編譯方式 15 C++ source code 可執行檔 C++ 編譯器
Qt 的編譯方式 16 C++ source code 可執行檔 C++ 編譯器 Qt
source code 神奇的 Qt 編譯器
17 說法太混,不能接受?…好吧。
真.C++ 編譯方式 18
真.Qt 編譯方式 19 如 moc_blabla.cpp Qt 大部分的程式碼原本就是標準 C++
打開你的 Qt creator 點選 File->New file or Project
開新專案 選擇 Other project 中的 Empty Qt project 在 Name 那一欄寫上專案的名稱 不要選擇 Shadow build (別緊張,方便觀察) next 到底! 20 DIY-1(1/3)
選擇 Add New->C++ Source File 新增 main.cpp ./main.cpp
21 DIY-1(2/3)
觀察 22 DIY-1(3/3)
qmake –project qmake make 23 Qt 操作流程
src/1/>ls main.cpp src/1/>qmake –project main.cpp 1.pro src/1/>qmake main.cpp 1.pro Makefile src/1/>make … src/1/>ls 1* 1.pro Makefile main.cpp main.o
Qt 可以分為兩個部分 函式庫 和 C++ 的一般的函式庫沒什麼不同 特殊功能
使用特殊功能,需要先經過 qmake 改造! 有一些函式庫需要使用 Qt 的特殊功能 24
Qt 的函式庫非常強大! 想想 KDE 吧~ 我們會先介紹
一些好用的巨集 一些好用的函式 一些好用的容器(container) 25 Qt 函式庫
問題,請條列印出三種動物chick, dog 和 pi 寫法一-使用 C++ 的 iterator
26 foreach(1/3)
寫法一 – c 寫法 27 foreach(2/3) 短很多,但 animalList[i] 是啥?
寫法三– 使用美美的 foreach 28 foreach(3/3) 快加入 python 的行列吧~~~ 注意!要引入
#include<QtGlobal>
想得到的函式前面加個 q 或 Q 即可 qrand() qAbs()
qSort() <- quick sort … 29 好用函式
C++ 的容器前面加個 Q 即可 用來完全取代 C++ 的容器
如 QList, QVector, QMap, QSet… QLinkedList, QStack, QQueue, QStringList… 30 容器 Container
最常用的 Container 不知道該用什麼 Container ?用 QList 就對了!
相容相當多種操作方式。 31 Container – QList(1/3)
QList 32 Container – QList(2/3)
size 的型態為 int 別當成 std::list 可由標準庫的 container
轉換 QList.fromStdList() QList.fromStdVector() QList.fromStdSet() … 33 Container – QList(3/3)
用來完全取代 std::string 裡面有一大堆處理字串的方法 replace, count, compare, insert,
append… 34 Container – QString(1/2)
C++ 的格式化字串很糟? std::cout<<a<<“ “<<b<<“:”<<a<<endl; 放心,我們還有 Qt
QString(“%1 %2:%1\n”).arg(a).arg(b); 35 Container – QString(2/2) 注意:Qstring 應該 Qt 自己的方法印出, 不能用 std::cout ,除非用 qPrintable()
QString 超常用 QList 非常常用 QList<QString> 非常超常常用 but QList<QString> 有
14 字!該死! 36 Container
只有 11 個字 -> Win 繼承自 QList<QString> ,並做了一些優化
37 Container - QStringList
萬物之始,Qt 的基礎 QObject~ 就像是 Java 的 Object
Qt Object Model 的核心 38 QObject(1/9)
這是一個關於 Qt 的非常溫馨的人倫故事。 Qt 的世界裡,每個物件都可以有自己的爸爸。 如果爸爸要死了,死前會把兒子全部殺掉。
若兒子要死了,死前會也通知一下自己的爸爸,免 得爸爸之後要殺死他的時候找不到人。 39 QObject(2/9)
40 QObject(3/9) 爸爸 兒子1 兒子2 兒子3 不要和繼承搞混!
現在~~我們設計一個 MyString 41 QObject(4/9)
然後~ 42 QObject(5/9) 還記得忘記 delete 的時光嗎?還是昨天還在發生呢?
其實可以改成 43 QObject(6/9) 重申一次,不要和繼承搞混了!
現在~ 44 QObject(7/9)
parent and children 可說是 Qt 賦予 C++ 類似
gc 的機制 對 Qt 來說是非常重要的機制 再重申一遍,不要被繼承搞混! 45 QObject(8/9) parent child gc: Garbage Collection
Object Model Signal and Slot 賦予 Qt 物件一些神奇的特性
46 QObject(9/9)
從前,有一隻小雞,名叫「處處」 而有另一隻小雞,名叫「顯顯」 47 QObject-Signal and Slot(1/7) 處處 顯顯
我負責給顯顯資料 我負責把資料顯示出來
處處會將資料傳給顯顯 顯顯在顯示完資料後,會通知處處 接到通知後,處處會再傳資料給顯顯 48 QObject-Signal and Slot(2/7)
顯顯 處處
第一種做法 處處要傳訊息給顯顯,所以必須「知道」顯顯 顯顯要通知處處,所以也必須「知道」處處 第二種做法 回呼
– 一般 GUI 框架會用的方式 第三種做法 Qt 的 signal and slot ~~ 49 QObject-Signal and Slot(3/7)
signal 每個繼承自 QObject 的類別都可以有這個功能 對自己狀態的宣示 自己不需要「知道」要通知誰 50
QObject-Signal and Slot(4/7) 處處 宣示:我處理完資料了 「我不需要知道誰會接到我資料」 「接到的人自己會去處理」
slot 每個繼承自 QObject 的類別都可以有這個功能 可以接受 signal 不需要「知道」會被誰通知,只要格式ok即可
51 QObject-Signal and Slot(5/7) 接受:我會顯示收到的資料 「我不需要知道是誰丟資料給我」 「不是顯 顯也行,誰給我,我就做」 顯顯
connect 函式 連接 signal 和 slot 讓
signal 和 slot 建立關連 connect(sender, signal, receiver, slot) 52 QObject-Signal and Slot(6/7)
connect 函式 connect(處處, 送資料, 顯顯, 顯示資料); connect(顯顯,
我搞定了, 處處, 繼續處理資料) QObject::connect(processorr, SIGNAL(send(string)), displayer, SLOT(display(string)) 53 QObject-Signal and Slot(7/7) SIGNAL, SLOT 是一個巨集
注意事項 .h Q_OBJECT signals slots 54 DIY(1/3) 處處=>
注意事項 .h Q_OBJECT signals slots 55 DIY(2/3) 顯顯=>
56 DIY(3/3)