目標(biāo)
為實(shí)現(xiàn)從QML字符串中創(chuàng)建QML對(duì)象,并顯示在基于QWidget項(xiàng)目工程中吠勘,且這個(gè)QML對(duì)象所屬類型來(lái)自QML插件
代碼
以下這段代碼是采用C++方式從QML字符串中創(chuàng)建QML對(duì)象并顯示在QTabWidget的某一頁(yè):
QTabWidget *tabw = ui->tabMessageListWidget;
....
QQuickWidget *qwWaveAnal=new QQuickWidget();
qwWaveAnal->setObjectName(QStringLiteral("qwWaveAnal"));
qwWaveAnal->setResizeMode(QQuickWidget::SizeRootObjectToView );
QQmlComponent *component = new QQmlComponent(qwWaveAnal->engine());
component->setData("import QtQuick 2.4\n import XjQmlUi 1.0 \n WaveAnalDemo{}", QUrl());
qwWaveAnal->setContent(QUrl(), component, component->create());
tabw->addTab(qwWaveAnal, QStringLiteral("波形分析"));
注意: import XjQmlUi 1.0 這句話呆奕,該模塊為QML插件磁奖,并包含了WaveAnalDemo這個(gè)QML類型的實(shí)現(xiàn)破加。