Load QQuickView from QByteArray
Load QQuickView from QByteArray
有没有办法用字符串数据加载QQuickView
?据我所知,只有void QQuickView::setSource(const QUrl & url)
.
我可以用字符串数据加载QQmlComponent
,但现在如何将此组件分配给QQuickView
?
您可以在创建QQmlComponent
时传递QQuickView
引擎:
QQmlComponent component(view->engine(), QUrl("path/to/file.qml"));
我最近遇到了这个问题,并使用这样的QQuickWindow::contentItem()
解决了这个问题。
...
int main(int argc, char ** argv)
{
QGuiApplication app(argc, argv);
QQuickView view;
QQmlComponent com(view.engine());
com.setData(QByteArrayLiteral("... QML source ..."), QUrl())
QQuickItem *root = qobject_cast<QQuickItem *>(com.create());
root->setParentItem(view.contentItem());
view.show();
return app.exec();
}
相关文章:
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 如何在QByteArray中放置和检索位字段而不会感到痛苦?
- 如何通过UDP接收QByteArray并将其解析为位字段结构?
- std::async from std::async in windows xp
- 将包含二进制数据的 QByteArray 传递到按值运行
- 如何将QByteArray转换为std::istream或std::ifstream?
- std::is_reference from std::any
- std::time_point from and to std::string
- "No suitable conversion function from 'std::string' to 'const char *' exists"
- std::chrono::time_point from std::string
- 为什么QByteArray的大小是"int"而不是"无符号int"
- 将 QByteArray 转换为无符号短:不符合预期
- Visual accept std::string from std::byte iterator
- 如何将由一系列十六进制值表示的枚举附加到 QByteArray?
- 如何使用 QByteArray 而不是 SNDFILE
- C++中链表的错误"Abort signal from abort(3) (sigabrt) "
- 如何在不复制的情况下操作 QByteArray 对象?
- Fill QByteArray from QAudioBuffer
- Load QQuickView from QByteArray
- Creating a QImage from QBytearray