Qt + Ogre3D. I cannot build a very simple example
-
Hello, I use:
- Qt 5.15.2 MinGW 32-bit Dynamic for Debug build
- Ogre 13.1.1 MinGW Static build
There is a class called ApplicationContextQt that can help to use Qt with Ogre3D but I have errors:
This example is very simple:
main.cpp
#include "Ogre.h" #include "OgreApplicationContextQt.h" #include <QGuiApplication> class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener { public: MyTestApp(); void setup(); bool keyPressed(const OgreBites::KeyboardEvent& evt); }; MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp") { } bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt) { if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } void MyTestApp::setup(void) { // do not forget to call the base first OgreBites::ApplicationContextQt::setup(); } int main(int argc, char *argv[]) { QGuiApplication qapp(argc, argv); MyTestApp app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); return qapp.exec(); }
.pro
QT += core gui INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE" LIBS += -lOgreBitesQtStatic LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp HEADERS += # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
-
Looks like the fact your application is so simple is the problem. You defined
MyTestApp
in the .cpp file and moc by default only runs on header files, so there's no meta information code generated for your QObject based class.Put that class declaration in a header and it should work.
-
I made Clean/Build. It is the same:
MyTestApp.h
#ifndef MYTESTAPP_H #define MYTESTAPP_H #include "Ogre.h" #include "OgreApplicationContextQt.h" class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener { public: MyTestApp(); void setup(); bool keyPressed(const OgreBites::KeyboardEvent& evt); }; #endif // MYTESTAPP_H
MyTestApp.cpp
#include "MyTestApp.h" MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp") { } bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt) { if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } void MyTestApp::setup(void) { // do not forget to call the base first OgreBites::ApplicationContextQt::setup(); }
main.cpp
#include <QGuiApplication> #include "MyTestApp.h" int main(int argc, char *argv[]) { QGuiApplication qapp(argc, argv); MyTestApp app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); return qapp.exec(); }
.pro
QT += core gui INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem" LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OgreBitesQtStatic" -lOgreBitesQtStatic LIBS += -L"E:/ProgramFiles/ogre-13.1.1/lib/OGRE" -lOgreBitesStatic LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE" LIBS += -lOgreBitesQtStatic LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreMeshLodGeneratorStatic -lOgreOverlayStatic -lOgrePagingStatic -lOgrePropertyStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ MyTestApp.cpp \ main.cpp HEADERS += \ MyTestApp.h # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
-
Hi,
Are you sure your Ogre libraries are in the correct order ?
It does matter with static linking. -
@SGaist said in Qt + Ogre3D. I cannot build a very simple example:
Are you sure your Ogre libraries are in the correct order ?
It does matter with static linking.I think it is not in this case. Problems with order looks like this:
-
I think that Ogre cannot work with qmake and I should use CMake instead of qmake:
-
I made everything like in this instruction: https://ogrecave.github.io/ogre/api/latest/setup.html#cmake
I added OGRE_DIR to Environment Variables (where
OGREConfig.cmake
is located):I created a new Qt Widget project with CMake instead of qmake:
I added this line from instruction above CMakeLists.txt:
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(BootstrapCMakeQt5Cpp SHARED ${PROJECT_SOURCES} ) else() add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) endif() endif() find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG) target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem)
But that tutorial works for shared libs only and does not work for static. So I have these errors:
CMake Error at CMakeLists.txt:44 (add_executable): Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? CMake Error at CMakeLists.txt:44 (add_executable): Target "BootstrapCMakeQt5Cpp" links to target "SDL2::SDL2" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
-
I see how to add OgreBitesQt here:
target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem)
But how to add BitesQt here:
find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG)
-
Then you should start by making a minimal Ogre only application build and then add Qt to the mix.
And if it still fails, you should check with the Ogre folks.
Note that you would likely have less trouble using a classic dynamic build of Ogre.
-
My goal now is to check can Ogre works with Qt for static or not. If it cannot I will continue usage of OpenGL, and I will not spend my time for Ogre. And I want to check can I integrate Ogre inside of Qt Widget for static build.
This message
Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target was not found.
says that I should to addZLIB::ZLIB
here:target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem ZLIB::ZLIB)
But before it I should to add this line:
find_package(ZLIB)
. Ogre already haszlib
. But it does not work again:find_package(ZLIB) find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG) target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem ZLIB::ZLIB)
It says again:
CMake Error at CMakeLists.txt:44 (add_executable): Target "BootstrapCMakeQt5Cpp" links to target "ZLIB::ZLIB" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
-
I solved the problems with SDL2 and ZLIB that was in the message above. Now configuration is passing. But when I build it i see the same errors like in the first post with qmake:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5) project(BootstrapCMakeQt5Cpp LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) link_directories("E:/ProgramFiles/ogre-13.1.1/lib") find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) set(PROJECT_SOURCES main.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(BootstrapCMakeQt5Cpp SHARED ${PROJECT_SOURCES} ) else() add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) endif() endif() #find_package(ZLIB REQUIRED) add_library(ZLIB::ZLIB INTERFACE IMPORTED) add_library(SDL2::SDL2 INTERFACE IMPORTED) find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG) target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem)
main.cpp
#include "Ogre.h" #include "OgreApplicationContextQt.h" #include <QGuiApplication> class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener { public: MyTestApp(); void setup(); bool keyPressed(const OgreBites::KeyboardEvent& evt); }; MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp") { } bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt) { if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } void MyTestApp::setup(void) { // do not forget to call the base first OgreBites::ApplicationContextQt::setup(); } int main(int argc, char *argv[]) { QGuiApplication qapp(argc, argv); MyTestApp app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); return qapp.exec(); }
-
I added OgreApplicationContextQt.cpp directly in my code:
I added Q_OBJECT to MyTestApp.h. I have a little different errors:
These are all my files:
MyTestApp.h
#ifndef MYTESTAPP_H #define MYTESTAPP_H #include "Ogre.h" #include "OgreApplicationContextQt.h" #include <QtCore/QObject> class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener { Q_OBJECT public: MyTestApp(); virtual ~MyTestApp() { } void setup(); bool keyPressed(const OgreBites::KeyboardEvent& evt); }; #endif // MYTESTAPP_H
MyTestApp.cpp
#include "MyTestApp.h" MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp") { } bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt) { if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } void MyTestApp::setup(void) { // do not forget to call the base first OgreBites::ApplicationContextQt::setup(); }
main.cpp
#include <QGuiApplication> #include "MyTestApp.h" int main(int argc, char *argv[]) { QGuiApplication qapp(argc, argv); MyTestApp app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); return qapp.exec(); }
.pro
QT += core gui INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\Bites" INCLUDEPATH += "E:\ProgramFiles\ogre-13.1.1\include\OGRE\RTShaderSystem" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib" LIBS += -L"E:\ProgramFiles\ogre-13.1.1\lib\OGRE" #LIBS += -lOgreBitesQtStatic # -lOgreMeshLodGeneratorStatic # -lOgrePagingStatic # -lOgrePropertyStatic LIBS += -lOgreBitesStatic -lRenderSystem_GL3PlusStatic -lOgreGLSupportStatic -lOgreOverlayStatic -lOgreRTShaderSystemStatic -lOgreVolumeStatic -lPlugin_BSPSceneManagerStatic -lPlugin_DotSceneStatic -lPlugin_OctreeSceneManagerStatic -lPlugin_OctreeZoneStatic -lPlugin_ParticleFXStatic -lPlugin_PCZSceneManagerStatic -lRenderSystem_GLES2Static -lRenderSystem_GLStatic -lOgreMainStatic -lOgreTerrainStatic -lCodec_STBIStatic -lzlibstatic LIBS += -lSDL2main -lSDL2.dll -lfreetype -lpugixml LIBS += -lopengl32 -lgdi32 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ MyTestApp.cpp \ OgreApplicationContextQt.cpp \ main.cpp HEADERS += \ MyTestApp.h # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
-
I try to compile the same very simple and basic example that I tried before with cmake. Сonfiguration with cmake was made without errors:
-- Found OGRE -- static : ON -- components : Bites;MeshLodGenerator;Overlay;Paging;Property;RTShaderSystem;Terrain;Volume -- plugins : Plugin_BSPSceneManager;Plugin_OctreeSceneManager;Plugin_PCZSceneManager;Plugin_ParticleFX;RenderSystem_GL;RenderSystem_GLES2;RenderSystem_GL3Plus;Codec_STBI -- media : E:/ProgramFiles/ogre-13.1.1/Media -- Configuring done -- Generating done -- Build files have been written to: E:/_Projects/Ogre3D/build-BootstrapCMakeQt5Cpp-Desktop_Qt_5_15_2_MinGW_32_bit-Debug Elapsed time: 00:01.
But when I build the project I see a few new errors
undefined reference to 'compressBound'
andundefined reference to 'compress'
in OgreSTBICodec.cpp:I added OgreApplicationContextQt.cpp to the project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.5) project(BootstrapCMakeQt5Cpp LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) link_directories("E:/ProgramFiles/ogre-13.1.1/lib") find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) set(PROJECT_SOURCES MyTestApp.h MyTestApp.cpp OgreApplicationContextQt.cpp main.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) else() if(ANDROID) add_library(BootstrapCMakeQt5Cpp SHARED ${PROJECT_SOURCES} ) else() add_executable(BootstrapCMakeQt5Cpp ${PROJECT_SOURCES} ) endif() endif() #find_package(ZLIB REQUIRED) add_library(ZLIB::ZLIB INTERFACE IMPORTED) add_library(SDL2::SDL2 INTERFACE IMPORTED) find_package(OGRE REQUIRED COMPONENTS Bites RTShaderSystem CONFIG) target_link_libraries(BootstrapCMakeQt5Cpp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets OgreBitesQt OgreRTShaderSystem)
MyTestApp.h
#ifndef MYTESTAPP_H #define MYTESTAPP_H #include "Ogre.h" #include "OgreApplicationContextQt.h" #include <QtCore/QObject> class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener { Q_OBJECT public: MyTestApp(); virtual ~MyTestApp() { } void setup(); bool keyPressed(const OgreBites::KeyboardEvent& evt); }; #endif // MYTESTAPP_H
MyTestApp.cpp
#include "MyTestApp.h" MyTestApp::MyTestApp() : OgreBites::ApplicationContextQt("OgreTutorialApp") { } bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt) { if (evt.keysym.sym == OgreBites::SDLK_ESCAPE) { getRoot()->queueEndRendering(); } return true; } void MyTestApp::setup(void) { // do not forget to call the base first OgreBites::ApplicationContextQt::setup(); }
main.cpp
#include <QGuiApplication> #include "MyTestApp.h" int main(int argc, char *argv[]) { QGuiApplication qapp(argc, argv); MyTestApp app; app.initApp(); app.getRoot()->startRendering(); app.closeApp(); return qapp.exec(); }
-
-
I use Ogre 13.6.3 and Qt 5.15.2 MinGW 64-bit and I have the same problem.
Did you get a solution?
-
This post is deleted!
-
This post is deleted!
-
@cpr0gr4mm3r Maybe my next topic will help you: Problems with Ogre in Qt Creator