QT官方文档阅读:Q3DBars例程的问题和使用(一)

介绍:Q3DBars是一个可视化3D条形图,可以通过鼠标自由移动视角。

1.官方例程

Q3DBars bars;
bars.setMinimumSize(QSize(256, 256));
bars.rowAxis()->setRange(0, 4);
bars.columnAxis()->setRange(0, 4);
QBar3DSeries *series = new QBar3DSeries;
QBarDataRow data;
data << QBarDataItem(1.0f) << QBarDataItem(3.0f) << QBarDataItem(7.5f) << QBarDataItem(5.0f)
         << QBarDataItem(2.2f);
series->dataProxy()->addRow(data);
bars.addSeries(series);
bars.show();

上述例程如果直接复制到你的QT代码中会直接报错,addRow会提示参数类型错误,在Qt6.7版本中addRow要求的参数类型是QBarDataRow指针

2.使用过程中的其他问题

在官方文档中Q3DBars是从QAbstract3DGraph Class继承过来的,而QAbstract3DGraph Class是继承QWidget。理论上说可以在QWidget和QMaindow作为父对象,在构造函数使用Q3DBars。

但是在QT creator中打开QAbstract3DGraph的库函数继承的是QWindow。所以目前简单使用Q3DBars只能构造一个QWindow类作为父类,或者直接在main函数中构造使用。

class Q_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions
explicit Q3DBars(const QSurfaceFormat *format = nullptr, QWindow *parent = nullptr);

初学QT,有错误的地方请大神指出。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用Qt 5.14中的SCXML功能的完整例程。 main.cpp: ```cpp #include <QCoreApplication> #include <QScxmlStateMachine> #include <QScxmlInvokableService> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // 创建状态机 QScxmlStateMachine stateMachine; stateMachine.setScxml("example.scxml"); // 创建可调用服务 QScxmlInvokableService service; QObject::connect(&service, &QScxmlInvokableService::send, [&stateMachine](const QString &event, const QVariant &data) { stateMachine.submitEvent(event, data); }); // 注册可调用服务 stateMachine.addInvokableService("exampleService", &service); // 启动状态机 stateMachine.start(); return a.exec(); } ``` example.scxml: ```xml <?xml version="1.0" encoding="UTF-8"?> <scxml version="1.0" xmlns="http://www.w3.org/2005/07/scxml" datamodel="ecmascript"> <state id="idle"> <onentry> <log label="stateEntry" expr="'Entering idle state'"/> </onentry> <transition event="testEvent" target="active"/> </state> <state id="active"> <onentry> <log label="stateEntry" expr="'Entering active state'"/> <send event="exampleSignal"/> </onentry> <transition event="exampleSignal" target="idle"/> </state> </scxml> ``` 在这个例子中,我们创建了一个简单的状态机,它有两个状态:idle和active。在idle状态中,当收到testEvent事件时,它将转换到active状态。在active状态中,当进入状态时,它将发送exampleSignal事件。当收到exampleSignal事件时,它将转换到idle状态。 我们还创建了一个可调用服务exampleService,它将用于发送事件到状态机。在main.cpp中,我们将可调用服务注册到状态机中,并启动状态机。 当运行程序时,你可以使用exampleService发送testEvent事件来触发状态转换。状态转换时,日志将记录在控制台中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值