I have solved my issue. Apparently when you install Qt through the .bin file they have on the site it does not change your path, which cmake relies on but QtCreator does not. To do this, edit your bash.bashrc file with superuser permission and add the following lines to the end of the file:
export QTDIR=/opt/qtsdk-2010.04/qt
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
export QTDIR=/opt/qtsdk-2010.04/qt
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
To copy to clipboard, switch view to plain text mode
If you use gnome, use: sudo gedit /etc/bash.bashrc, for KDE I think you would use: sudo kate /etc/bash.bashrc
Also you may have to modify line 1 to match your own QT installation directory.
Modify the following file for your CMakeLists.txt project:
# You must set the minimum version for CMake
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# This is the name of your project:
PROJECT(ObjDetect_proj)
SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_CXX_FLAGS "-Wall")
# Use this for additional packages you need support for. In this case, I am using OpenCV.
# Consult CMake documentation to see which packages are supported and what the command is.
FIND_PACKAGE( OpenCV REQUIRED )
# QT4 Handling
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE_DIRECTORIES( ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
INCLUDE(${QT_USE_FILE})
# Change these to all your header files
SET( HWQ_Qt4_SRC
src/MainWindow.h
src/ObjDetect.h
)
# Change this to all your .ui designer files
SET( HWQ_Qt4_UI
src/MainWindow.ui
)
# Add resource files if you have them.
SET( HWQ_Qt4_RES
)
# This runs the QT MOC
QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC})
# This creates your ui_whatever.h files
QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI})
QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES})
INCLUDE_DIRECTORIES( . )
# Put your cpp files here
SET( HWQ_SRC
src/main.cpp
src/MainWindow.cpp
src/ObjDetect.cpp
${HWQ_MOC_CPP}
${HWQ_UI_CPP}
${HWQ_RES_H}
)
SET( HWQ_LIB
${QT_LIBRARIES}
)
ADD_EXECUTABLE(ObjDetect ${HWQ_SRC} )
TARGET_LINK_LIBRARIES(ObjDetect ${HWQ_LIB} ${OpenCV_LIBS} )
# I think this line only gets called when you run 'make install'
INSTALL_TARGETS( /bin Objdetect)
# You must set the minimum version for CMake
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
# This is the name of your project:
PROJECT(ObjDetect_proj)
SET(CMAKE_BUILD_TYPE Release)
SET(CMAKE_CXX_FLAGS "-Wall")
# Use this for additional packages you need support for. In this case, I am using OpenCV.
# Consult CMake documentation to see which packages are supported and what the command is.
FIND_PACKAGE( OpenCV REQUIRED )
# QT4 Handling
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE_DIRECTORIES( ${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
INCLUDE(${QT_USE_FILE})
# Change these to all your header files
SET( HWQ_Qt4_SRC
src/MainWindow.h
src/ObjDetect.h
)
# Change this to all your .ui designer files
SET( HWQ_Qt4_UI
src/MainWindow.ui
)
# Add resource files if you have them.
SET( HWQ_Qt4_RES
)
# This runs the QT MOC
QT4_WRAP_CPP(HWQ_MOC_CPP ${HWQ_Qt4_SRC})
# This creates your ui_whatever.h files
QT4_WRAP_UI(HWQ_UI_CPP ${HWQ_Qt4_UI})
QT4_ADD_RESOURCES(HWQ_RES_H ${HWQ_Qt4_RES})
INCLUDE_DIRECTORIES( . )
# Put your cpp files here
SET( HWQ_SRC
src/main.cpp
src/MainWindow.cpp
src/ObjDetect.cpp
${HWQ_MOC_CPP}
${HWQ_UI_CPP}
${HWQ_RES_H}
)
SET( HWQ_LIB
${QT_LIBRARIES}
)
ADD_EXECUTABLE(ObjDetect ${HWQ_SRC} )
TARGET_LINK_LIBRARIES(ObjDetect ${HWQ_LIB} ${OpenCV_LIBS} )
# I think this line only gets called when you run 'make install'
INSTALL_TARGETS( /bin Objdetect)
To copy to clipboard, switch view to plain text mode
Now I don't know why exactly, but when you run CMake from Qt Creator, it screws up. You have to go to the command line first and run
cmake .
cmake .
To copy to clipboard, switch view to plain text mode
After you run this initially, you can open the CMakeLists.txt file with QtCreator and it will open your whole project and build and link correctly.
I hope this helps some other poor sucker trying to figure this stuff out.
-Greg
Bookmarks