【转载】Qt6.2.4 qml ChartView 实现饼状图与问题解决
作者:互联网
转载
环境
环境 | 版本 |
---|---|
windows | 10 |
QT | 6.2.4 |
Qt Creator | 8.0.1 (Community) |
qmake |
注意
如果直接在 qml 中使用 ChartView 项目编译不通过/编译失败,报错如下:
Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
预览
正文
- 需要在 .pro 文件中追加 charts
QT += quick charts
- main.cpp 使用 QGuiApplication 初始化 app 会报错,需要切换为 QApplication
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QApplication>
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
// QGuiApplication app(argc, argv);
QApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
- 在 qml 文件中引入 QtCharts ,并使用 ChartView 绘制
import QtQuick 2.15
import QtQuick.Window 2.15
import QtCharts 2.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
ChartView {
width: 400
height: 300
theme: ChartView.ChartThemeBrownSand
antialiasing: true
PieSeries {
id: pieSeries
PieSlice { label: "eaten"; value: 94.9 }
PieSlice { label: "not yet eaten"; value: 5.1 }
}
}
}
标签:Qt6.2,QT,url,app,qml,ChartView,yet 来源: https://www.cnblogs.com/xiaqiuchu/p/16654536.html