StocQt
一款可配置的100只股票图表工具。

StocQt应用程序基于纳斯达克 100 指数,为用户自定义的 100 只股票列表提供趋势图表。用户可从列表中选择股票。该应用程序还允许用户将最多 5 只股票加入收藏,以便在对比图表中使用。
该应用程序使用了多种自定义类型,例如 Search、StockCheckBox、StockChart、StockView 和 SettingsView。这些类型以易于阅读的形式呈现股票数据,并允许用户自定义趋势图。例如,用户可以选择查看股票价格的周线、月线、季度线或半年线走势。
该应用程序使用一个用 C++ 实现的自定义 StockEngine 单例类来处理数据,例如 API 请求和将股票加入收藏。它实现了一个自定义的 APIHandler 类来获取在线数据。
void ApiHandler::stockHistory(const QString &symbol,
std::function<void(QList<HistoryData>)> onComplete)该应用程序使用 `ObjectModel ` 类型来访问其依赖的可视化数据模型。
id: mainWindow
...
ListView {
id: root
...
model: ObjectModel {
Item {
id: stockContainer
width: root.width
height: root.height
StockView {
id: stockView
anchors.fill: parent
visible: false
width: root.width
height: root.height
stateGroup: stateList
}
StockListView {
id: listView
visible: true
anchors.fill: parent
width: root.width
height: root.height
stateGroup: stateList
}
}
FavoriteView {
id: favoriteView
width: root.width
height: root.height
}
SettingsView {
id: infoView
width: root.width
height: root.height
}
}
}StockListModel 是一个自定义数据模型,列出了包含股票 ID、名称、价格和收藏状态等基本信息的股票列表。当用户希望从列表中选择另一只股票时,该应用程序会使用此数据模型。
StockView 和 FavoriteView 是复杂的数据模型,用于显示所选股票或最多 5 只股票组的趋势图表。 它们使用另一个自定义类型 StockChart 或 FavoriteChart,该类型从 StockEngine 加载数据到 ListModels 中,并使用 Surface3D、Bars3D 或 Scatter3D 呈现股价的趋势图。
Rectangle {
id: chart
...
function updateHistory(){
updateStartDate()
let startPoint = StockEngine.stockModel.indexOf(startDate)
let totalPoints = StockEngine.stockModel.historyCount()
let width = startPoint / 50
for (let i = 0; i < totalPoints; i++) {
let epochInDays = StockEngine.stockModel.historyDate(i, false) / 86400
appendSurfacePoint(openModel, width, epochInDays, StockEngine.stockModel.openPrice(i))
appendSurfacePoint(closeModel,width, epochInDays, StockEngine.stockModel.closePrice(i))
appendSurfacePoint(highModel,width, epochInDays, StockEngine.stockModel.highPrice(i))
appendSurfacePoint(lowModel,width, epochInDays, StockEngine.stockModel.lowPrice(i))
}
...
Surface3D {
id: historyGraph
...
Surface3DSeries {
id: highSeries
visible: true
baseColor: "green"
shading: Surface3DSeries.Shading.Flat
drawMode: Surface3DSeries.DrawSurface
itemLabelFormat: "Time: @xLabel High:@yLabel$"
ItemModelSurfaceDataProxy {
itemModel: highModel
rowRole: "row"
columnRole: "column"
yPosRole: "value"
}
},SettingsView 展示有关应用程序的信息。
若要更深入地了解该应用程序,请使用Qt Creator 或Visual Studio Code浏览其代码。
运行示例
您可以通过以下方式运行示例:
- Qt Creator
打开Welcome 模式,并从Examples 中选择该示例。有关更多信息,请参阅Qt Creator :教程:构建和运行。
- Qt Extension for Visual Studio Code
在Command Palette 中运行Qt: Open Qt examples 命令,然后从列表中选择该示例。有关更多信息,请参阅Qt Extension for Visual Studio Code :教程:构建和运行。
另请参阅 QML 应用程序。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.