Qt 範例和教程

Qt 提供一批代碼樣本和教程,以幫助新用戶入門 Qt 開發。這些文檔涵蓋一係列話題、從 Widget 的基本用法到分步教程,以展示如何把應用程序拼湊在一起。

範例是 Qt 包的一部分。請拜訪 下載 頁麵,瞭解更多信息。

運行範例

打開和運行範例在 Qt Creator 歡迎 模式。大多數範例可在各平颱上運行且可搜索特定平颱範例,在搜索字段中鍵入平颱名稱 (或任何關鍵字)。例如,鍵入 Android 在搜索字段中列錶完全兼容 Android 的範例。

有關在 Qt Creator 中運行範例的更多信息,拜訪 構建和運行範例 頁麵。

要查看所有 Qt 範例的列錶,請拜訪 Qt 範例列錶 頁麵。

Application Examples

Calqlatr A Qt Quick app designed for portrait devices that uses custom components, animated with AnimationController, and JavaScript for the application logic.
Coffee Machine A Qt Quick application with a state-based custom user interface.
Document Viewer A Widgets application to display and print Json, text and PDF files. Demonstrates various features to use in widget applications: Using QSettings, query and save user preferences, manage file histories and control cursor behavior when hovering over widgets.
照片錶麵 A QML app for touch devices that uses a Repeater with a FolderListModel to access content in a folder, and a PinchHandler to handle pinch gestures on the fetched content.
食譜瀏覽器 Injecting custom stylsheets into web pages and providing a rich text preview tool for a custom markup language

Connectivity

注解 URL (統一資源定位符) Example shows reading from formatted NFC Data Exchange Format (NDEF) messages
Blocking Receiver Shows how to use the synchronous API of QSerialPort in a non-GUI thread
Blocking Sender Shows how to use the synchronous API of QSerialPort in a worker thread
藍牙聊天 Shows communication through Bluetooth using RFCOMM protocol
藍牙低功耗心率遊戲 A game demonstrating the interaction with a Bluetooth Low Energy Heart Rate device/service
藍牙低功耗心率服務器 An example demonstrating how to set up and advertise a GATT service. The example demonstrates the use of the Qt Bluetooth Low Energy classes related to peripheral (slave) functionality
藍牙低功耗掃描器 An application designed to browse the content of Bluetooth Low Energy peripheral devices. The example demonstrates the use of all Qt Bluetooth Low Energy classes
CAN Bus Manager Example sends and receives CAN bus frames
Modbus Client Example implements a Modbus client application
Modbus Custom Command Example shows how to handle custom Modbus function codes
Modbus Server Example implements a Modbus server application
Serial Terminal Shows how to use various features of QSerialPort

桌麵

計算器構建器 Creating a user interface from a Qt Designer form at run-time
計算器錶單 在應用程序中使用采用 Qt Designer 創建的錶單
Calculator Form/Multiple Inheritance 在應用程序中使用采用 Qt Designer 創建的錶單
容器擴展範例 Creating a custom multi-page plugin for Qt Designer
自定義 Widget 插件 Creating a custom widget plugin for Qt Designer
任務菜單擴展 Creating a custom widget plugin for Qt Designer and providing custom task menu entries that are associated with the plugin
文本查找器 Dynamically loading .ui files using QUiLoader

Embedded

Custom Shell Custom Shell shows how to implement a custom shell extension
IVI Compositor IVI Compositor is an example that demonstrates how to use the IviApplication extension
Minimal QML Minimal QML is a simple example that demonstrates how to write a Wayland compositor in QML
Multi Output Multi Output is an example that demonstrates a compositor with multiple outputs
Multi Screen Multi Screen is a desktop-style Wayland compositor for multiple screens
Overview Compositor Overview Compositor shows how to switch between clients in a grid
Pure QML Pure QML is an example that demonstrates how to write a Wayland compositor in pure QML
QtShell Compositor QtShell Compositor shows how to use the QtShell shell extension
Server Side Decoration Compositor Server Side Decoration Compositor is a simple example that demonstrates server side window decorations on xdg-shell
Spanning Screens Spanning Screens is an example that demonstrates how to let Wayland clients span multiple screens

圖形

指針式時鍾 Analog Clock example shows how to draw the contents of a custom widget
Axis Handling Implementing axis dragging with a custom input handler in QML, and creating a custom axis formatter
Graph Gallery Gallery of Bar, Scatter, and Surface graphs
Simple Bar Graph Using Bars3D in a QML application
Simple Scatter Graph Using Scatter3D in a QML application
Surface Graph Gallery Gallery with three different ways to use a Surface3D graph
Volumetric Rendering Rendering volumetric objects
Wiggly Demonstrates how to use an effect created with the Qt Quick Effect Maker (QQEM)

Input/Output

Convert Example Convert example demonstrates how to convert between different serialization formats
DOM Bookmarks Application 提供用於 XML 書簽交換語言文件的讀取器
JSON 保存遊戲範例 JSON Save Game example demonstrates how to save and load a small game using QJsonDocument, QJsonObject and QJsonArray
Parsing and displaying CBOR data A demonstration of how to parse files in CBOR format
QXmlStream 書簽範例 演示如何讀寫 XBEL 文件

國際化

Arrow Pad 範例 理解 Qt Linguist 上下文概念和使用 2 種或多種語言
Hello tr() 範例 將小 Hello World 程序翻譯成拉丁語
I18N 範例 Demonstrates Qt's support for translated text
Troll Print 範例 更新用於稍後發行的翻譯

移動

In-App purchasing demo A complete mobile application that demonstrates purchasing in-app products.
Qt Android Notifier Demonstrates calling Java code from Qt in an Android application

Networking

阻塞 Fortune 客戶端 演示如何為網絡服務創建客戶端
聊天 Using the Qt GRPC client API in the user applications
Fortune 客戶端 演示如何為網絡服務創建客戶端
Fortune 服務器 演示如何為網絡服務創建服務器
HTTP Client 演示簡單 HTTP 客戶端
Magic 8 Ball Creating a HTTP2 connection between a Qt GRPC client and a C++ gRPC server
多點播送接收器 演示如何接收發送給多點播送組的信息
多點播送發送器 演示如何把消息發送給多點播送組
QML WebSocket Client Explains how to write a QML WebSocket client example
QML WebSocket Server A simple example that shows how to use a QML WebSocketServer
Qt Quick Demo - RESTful Color Palette API client Example of how to create a RESTful API QML client.
Qt WebSockets 範例 List of Qt WebSocket examples
SCXML FTP Client 使用狀態機實現簡單 FTP 客戶端
Secure WebSocket Echo Client A simple client application using secure WebSockets (wss)
Secure WebSocket Echo Server A simple server to respond to clients over secure WebSockets (wss)
傳感器 Sensors example shows how two applications can communicate by sending protobuf messages using UDP sockets
Simple WebSocket Chat A minimal chat application using the WebSocket protocol
綫程化 Fortune 服務器 Threaded Fortune Server example shows how to create a server for a simple network service that uses threads to handle requests from different clients. It is intended to be run alongside the Fortune Client example
WebSocket Echo Client Show how to write a simple WebSocket client application
WebSocket Echo Server Show how to write a simple WebSocket server application

Positioning & Location

Log File Position Source (C++) Logfile Position Source shows how to create and work with a custom position source. It can be useful for simulating GPS data, or when the data is received in some custom format
SatelliteInfo (QML) SatelliteInfo example shows the available satellites using Sky View or RSSI View and the user's current position. The satellites currently contributing to the GPS fix are marked as pink
Weather Info (C++/QML) Weather Info example shows how to use the user's current position to retrieve local content from a web service in a C++ plugin for QML

社區範例

要查看和運行由 Qt 工程提供的範例,拜訪 社區範例 頁麵。

所有範例

所有 Qt 範例 列齣瞭按其所屬 Qt 模塊分類的所有範例。