qt for android 使用qml加载osg模型闪退
怪我咯
怪我咯 2017-04-17 14:32:06
[Android讨论组]

首先这个是测试程序在电脑端运行时候的效果图


该工程的目录结构


main.qml文件

遇到的一些问题:
1)在qml中的source传入绝对路径,不能成功加载函数
其对应C++端代码如下

这样传入的路径前面会自动添加 qrc:/,导致不能正确找到osg文件
(我暂时在C++端将路径写死,现在可以寻找到文件,并且成功加载)

2)渲染osg模型闪退(目前最重要的问题)
该工程首先通过继承QQuickItem和QObject,在C++端实现模型加载、一些事件和模型的渲染
然后通过注册成组件,在qml中调用(import osgQtQuick)。
这样写在PC端没有问题,可以出来界面。
但是在Android端会崩溃,崩溃的代码定位到了这边。

我想知到有人试过用qml加载osg模型么?
或者有谁遇到过类似的问题么?谢谢

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
PHP中文网
  1. 只要.qml文件加入到qrc文件中(Qt for Android推荐使用qrc),在qml设置如source的路径时,非远程(http等)和非file:///开头的,都从qrc资源文件里面找。如果非从sdcard中加载,就用file:///开头。

  2. osg整合到QtQuick确实有点复杂,要了解Quick渲染的实现机制,官方文件也说了支持在Quick加混合使用OpenGL,但有一些要注意的地方,一些官方原文抄录如下:

Integration with OpenGL

It is possible to integrate OpenGL calls directly into the QQuickWindow using the same OpenGL context as the Qt Quick Scene Graph. This is done by connecting to the QQuickWindow::beforeRendering() or QQuickWindow::afterRendering() signal.

Note: When using QQuickWindow::beforeRendering(), make sure to disable clearing before rendering with QQuickWindow::setClearBeforeRendering().

Warning: It is crucial that OpenGL operations and interaction with the scene graph happens exclusively on the rendering thread, primarily during the updatePaintNode() phase.

Warning: As signals related to rendering might be emitted from the rendering thread, connections should be made using Qt::DirectConnection.

因我之前没做过类似的东西,所以无法给你提供更详细的帮助,但我觉得官方文档这几点“注意”是很重要的。还有例子源代码中有这一句:

void frame() {
        if (!compositeViewer.valid()) return;

        // Qt bug!?
        QOpenGLContext::currentContext()->functions()->glUseProgram(0); //这里是否必要??

        compositeViewer->frame();
    }
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号