QT,qApp-> applicationDirPath和CMakeLists

时间:2015-05-12 21:04:34

标签: qt cmake

我有一个应用程序可以使用QT-Creator(设置#1)进行编译和运行。

我刚刚创建了一个CMakeLists文件,这样人们就可以在不使用QT-Creator(设置#2)的情况下编译它,只需使用cmake。

使用设置#2进行编译是成功的。但是,当我运行应用程序时,一些路径会得到一个奇怪的值。

例如,我有代码段:

        QDir                   qdir( qApp->applicationDirPath() );
                               qdir.cdUp();
                               qdir.cdUp();
        QString         PATH = qdir.path() + "/config/" + QString( ui->myPaths_TextBox_Filename_INPUT_TXT->toPlainText() );

当我使用设置#1运行时,PATH字符串具有有效路径。 当我使用设置#2运行时,PATH字符串有一个奇怪的路径,如:

"/home/dimitris/.local/share/Trash/config/INPUT_PATHS.txt"

指向垃圾文件夹中的内容。

这是什么原因以及可能的解决方案是什么?到目前为止,我无法在网上找到这个有效的理由。

更新:

CMakeLists文件的内容:

project(RGBD_HAND_TRACKER)
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories( ${PROJECT_SOURCE_DIR}/include)

set(CMAKE_AUTOMOC ON)

# makes sure that it is compiled with 02 (O3 and up gives bad result)
set ( CMAKE_CXX_FLAGS "-O2"
    CACHE STRING "g++ Compiler Flags for All Builds" FORCE)
set ( CMAKE_CXX_FLAGS_DEBUG "-g"
    CACHE STRING "g++ Compiler Flags for Debug Builds" FORCE)
set ( CMAKE_CXX_FLAGS_RELEASE  "-DNDEBUG"
    CACHE STRING "g++ Compiler Flags for Release Builds" FORCE)
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO  "-DNDEBUG"
    CACHE STRING "g++ Compiler Flags for Release Builds" FORCE)
set ( CMAKE_CXX_FLAGS_MINSIZEREL  "-DNDEBUG"
    CACHE STRING "g++ Compiler Flags for Release Builds" FORCE)

find_package( PkgConfig )
pkg_check_modules( EIGEN3 REQUIRED eigen3 )
include_directories( ${EIGEN3_INCLUDE_DIRS} )

# Opencv required
find_package(OpenCV COMPONENTS core highgui imgproc REQUIRED)
include_directories(${OPENCV_INCLUDE_DIRS})
link_directories(${OPENCV_LIBRARY_DIRS})
add_definitions(${OPENCV_DEFINITIONS})

message("\n Found OpenCV \n")

# OpenGL required
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)

find_package (Threads)

# QT4 required
find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL REQUIRED)
set(QT_USE_QTOPENGL TRUE)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

message("\n Found QT4 \n")

INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIR} )

# PCL required
find_package(PCL 1.3 REQUIRED COMPONENTS common features filters io kdtree octree surface search) # keypoints registration sample_consensus segmentation tracking visualization apps io_ply
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

message("\n Found PCL \n")

# BOOST required
find_package( Boost REQUIRED COMPONENTS system thread )
include_directories( ${Boost_INCLUDE_DIRS} )

message("\n Found BOOST \n")

# BULLET required
find_package( Bullet REQUIRED COMPONENTS BulletDynamics BulletCollision BulletLinearMath 2.82 ) # BulletLinearMath BulletSoftBody
include_directories( ${BULLET_INCLUDE_DIRS} )

message("\n Found BULLET \n")

# GLM required
#INCLUDE_DIRECTORIES( ${PATH_GLM} )
include_directories( ../libraries/glm )

message("\n Found GLM \n")

# LIBCONFIG required
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package( LibConfig REQUIRED )
include_directories( ${LIBCONFIGPP_INCLUDE_DIR} )
#set(LIBS ${LIBS} ${LIBCONFIG_LIBRARIES})

message("\n Found LIBCONFIG \n")

# GLPK required
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package( GLPK REQUIRED )
include_directories( ${GLPK_INCLUDE_DIR} )

message("\n Found GLPK \n")

# MPFR required
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package( MPFR REQUIRED )
include_directories( ${MPFR_INCLUDE_DIRS} )
add_definitions(${MPFR_DEFINITIONS})

message("\n Found MPFR \n")

# GMP required
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package( GMP REQUIRED )
include_directories( ${GMP_INCLUDE_DIRS} )
add_definitions(${GMP_DEFINITIONS})

message("\n Found GMP \n")

# CGAL required
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package( CGAL REQUIRED )
include_directories( ${CGAL_INCLUDE_DIRS} )
add_definitions(${CGAL_DEFINITIONS})

message("\n Found CGAL \n")

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

file(GLOB VIEWER_SOURCES src/*.cpp)

file(GLOB VIEWER_INCLUDES include/*.h)

#set QT forms
SET(QT_FORMS
    ui/mainwindow.ui
)

# create moc for QT
QT4_WRAP_CPP(QT_MOC ${QT_HEADERS})

# process ui
QT4_WRAP_UI(QT_FORMS_HEADERS ${QT_FORMS})

ADD_EXECUTABLE(RGBD_HAND_TRACKER ${VIEWER_SOURCES} ${VIEWER_INCLUDES}
${QT_HEADERS}
${QT_MOC}
${QT_FORMS})

TARGET_LINK_LIBRARIES(RGBD_HAND_TRACKER ${OPENGL_LIBRARIES}     ${GLUT_LIBRARIES} ${QT_LIBRARIES} ${OpenCV_LIBS} ${CMAKE_THREAD_LIBS_INIT}     ${PCL_COMMON_LIBRARIES} ${PCL_FEATURES_LIBRARIES} 
${PCL_FILTERS_LIBRARIES} ${PCL_IO_LIBRARIES} ${PCL_KDTREE_LIBRARIES}     ${PCL_OCTREE_LIBRARIES} ${PCL_SURFACE_LIBRARIES} ${PCL_SEARCH_LIBRARIES} 
${Boost_SYSTEM_LIBRARIES} ${Boost_THREAD_LIBRARIES} 
${BULLET_DYNAMICS_LIBRARY} ${BULLET_COLLISION_LIBRARY} LinearMath 
${LIBCONFIGPP_LIBRARIES} ${GLPK_LIBRARIES} ${CGAL_LIBRARIES}         ${MPFR_LIBRARIES} 
) # ${BULLET_LINEARMATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY}
set_property(TARGET RGBD_HAND_TRACKER PROPERTY COMPILE_DEFINITIONS QT_SHARED _REENTRANT)

0 个答案:

没有答案