环境:vs2022 qt5.14
按照网上的教程先是编译库,编译osg 3.6.5 成功了,显示了牛,
按照该方法,成功了
后续编译ogsqt 以及ogsearth 一直失败,报错
该教程感觉太复杂了,放弃了
后来参考的别人编译好的库
博客地址
下载地址下载已经编译好的各种库,然后开始qt嵌入显示地球。
开始参考网上的例子(dll文件要拷到exe文件目录下),地球显示是白的,后来将ogsearth源码中的data文件夹拷入exe目录,结果正常了(原因是qt提示exe目录下data/woorld.tif 没有打开,然后搜索一下正好data文件夹中有这个文件,直接就拷贝过来了,结果ok了,刚开始学,好多东西都不清楚是干啥的,瞎猫碰对了)。
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
osgshowwidget.cpp
HEADERS += \
osgshowwidget.h
FORMS += \
osgshowwidget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#D:/2024/demo/Sniffer-Master/Lib/
win32:CONFIG(release, debug|release): LIBS += -L$$$$PWD/../ogsearth/lib/ -losg -losgDB -losgUtil -losgViewer -losgGA -losgWidget -lOpenThreads
else:win32:CONFIG(debug, debug|release): LIBS += -L$$$$PWD/../ogsearth/lib/ -losgd -losgDBd -losgUtild -losgViewerd -losgGAd -losgWidgetd -lOpenThreadsd
else:unix: LIBS += -L$$$$PWD/../ogsearth/lib/ -losg -losgDB -losgUtil -losgViewer -losgGA -losgWidget -lOpenThreads
INCLUDEPATH += $$PWD/../ogsearth/include
DEPENDPATH += $$PWD/../ogsearth/include
win32:CONFIG(release, debug|release): LIBS += -L$$$$PWD/../ogsearth/osgQt-osg3.7.0/lib/ -losgQOpenGL
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../ogsearth/osgQt-osg3.7.0/lib/ -losgQOpenGLd
else:unix: LIBS += -L$$PWD/../ogsearth/osgQt-osg3.7.0/lib/ -losgQOpenGL
INCLUDEPATH += $$PWD/../ogsearth/osgQt-osg3.7.0/include
DEPENDPATH += $$PWD/../ogsearth/osgQt-osg3.7.0/include
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../ogsearth/osgearth3.4/lib/ -losgEarth
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../ogsearth/osgearth3.4/lib/ -losgEarthd
else:unix: LIBS += -L$$PWD/PWD/../ogsearth/osgearth3.4/lib/ -losgEarth
INCLUDEPATH += $$PWD/../ogsearth/osgearth3.4/include
DEPENDPATH += $$PWD/../ogsearth/osgearth3.4/include
#include <QCoreApplication>
#include <QApplication>
#include <QDir>
#include "osgshowwidget.h"
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/EarthManipulator>
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osg/ArgumentParser>
#include <osgViewer/Viewer>
#include <QWidget>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include<osgGA/FlightManipulator>
#include <osgViewer/View>
#include <osgQOpenGL/osgQOpenGLWidget>
#include <osg/Timer>
#include <osg/ArgumentParser>
#include <osgGA/CameraManipulator>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// // 获取可执行文件的目录
osgShowWidget w;
w.show();
// 初始化osgViewer
// 初始化osgEarth
// osgEarth::initialize();
// osg::ArgumentParser args(&argc, argv);
// // 创建Viewer实例
// osgViewer::Viewer viewer(args);
// // 使用相对于exe的相对路径来构建.earth文件的完整路径
// QString relativeEarthFilePath = "Maps/ocean.earth"; // 请替换为你实际的.earth文件相对路径
// QString earthFilePath = exeDir + "/" + relativeEarthFilePath;
// // 请替换为你实际的.earth文件路径
// osg::ref_ptr<osg::Node> earthNode = osgDB::readNodeFile(earthFilePath.toStdString());
// if (!earthNode) {
// std::cerr << "Failed to load .earth file: " << earthFilePath.toStdString() << std::endl;
// return -1; // 如果加载失败,返回错误码
// }
// // 设置场景数据为加载的.earth文件
// viewer.setSceneData(earthNode.get());
// // 设置地球操控器
// viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator(args));
// // 运行Viewer
// return viewer.run();
return a.exec();
}
入图片描述