widget.cpp:170:33: error: no viable conversion from 'osgEarth::SkyNode *' to 'osg::ref_ptr<osg::Drawable>' ref_ptr:37:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'osg::Drawable *' for 1st argument ref_ptr:38:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'const osg::ref_ptr<osg::Drawable> &' for 1st argument ref_ptr:40:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'observer_ptr<osg::Drawable> &' for 1st argument ref_ptr:39:31: note: candidate template ignored: could not match 'ref_ptr<type-parameter-0-0>' against 'osgEarth::SkyNode *'
时间: 2024-02-06 12:01:58 浏览: 26
看起来你正在将 `osgEarth::SkyNode` 类型的对象直接赋值给了 `osg::ref_ptr<osg::Drawable>` 类型的变量,这是不兼容的,因为 `SkyNode` 并不是继承自 `Drawable`。
正确的写法应该是创建一个 `osg::Geode` 对象,将 `SkyNode` 添加到 `osg::Geode` 中,然后将 `osg::Geode` 添加到场景图中。以下是一个示例代码:
```
osg::ref_ptr<osg::Geode> skyGeode = new osg::Geode();
osg::ref_ptr<osgEarth::Util::SkyNode> skyNode = new osgEarth::Util::SkyNode(osgEarth::Util::SkyOptions());
skyGeode->addDrawable(skyNode.get());
root->addChild(skyGeode.get());
```
这将创建一个 `osgEarth::Util::SkyNode` 对象,并将其添加到 `osg::Geode` 中,然后将 `osg::Geode` 添加到场景图中。
相关问题
No viable conversion from 'shared_ptr<TalMsgChannel::TalMsgChannelClientCore>' to 'shared_ptr<TalMsgChannelBase>'
这个错误提示表示无法从 `shared_ptr<TalMsgChannel::TalMsgChannelClientCore>` 转换为 `shared_ptr<TalMsgChannelBase>`。这是因为 `shared_ptr` 是智能指针,具有类型安全的特性,不能直接进行不相关类型之间的转换。
要修复这个错误,你可以使用 `static_pointer_cast` 或者 `dynamic_pointer_cast` 来进行类型转换。例如,你可以使用 `static_pointer_cast` 将 `shared_ptr<TalMsgChannel::TalMsgChannelClientCore>` 转换为 `shared_ptr<TalMsgChannelBase>`,如下所示:
```cpp
std::shared_ptr<TalMsgChannel::TalMsgChannelClientCore> clientCorePtr = ...;
std::shared_ptr<TalMsgChannelBase> basePtr = std::static_pointer_cast<TalMsgChannelBase>(clientCorePtr);
```
注意,在进行这种类型转换时,确保派生类确实是基类的子类,否则可能会导致运行时错误。
D:\QTprojiect\Data_Analysis_tool\main.cpp:14: error: no viable conversion from 'QAxObject *' to 'QAxObject'
这个错误是因为你在进行类型转换时出了问题。可能是因为你在某些地方使用了指针而不是实际的对象,导致编译器无法正确地进行类型转换。
建议你仔细检查代码中涉及到类型转换的地方,确认是否使用了正确的对象或指针,并确保代码中所有需要进行类型转换的地方都能够正确地进行转换。另外,你也可以考虑使用动态类型转换(dynamic_cast)来避免这种类型转换错误的发生。