Qt with C Make
← Qt Painter Example | ● | Qt with DCMTK →
The previously drescribed Qt modules make up a basic Qt application that serves as framework for upcoming applications. It is also available from svn:
svn checkout https://svn.code.sf.net/p/vis-framework/code/trunk/ vis-framework
To compile it we use CMake.
We assume that there is a main module main.cpp and one additional widget module mainwindow.cpp/.h. Then the CMake file needs to take care of compilation and linkage of those two application modules. CMake handles that automatically if told so:
# cmake build file PROJECT(MyQtProject) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) # application name SET(APPNAME myqtapp) # non-standard path to Qt4 SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}; /usr/local/Trolltech/Qt-4.7.4; ) # Qt4 dependency SET(QT_USE_QTOPENGL TRUE) FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui REQUIRED) INCLUDE(${QT_USE_FILE}) ADD_DEFINITIONS(${QT_DEFINITIONS}) # OpenGL dependency FIND_PACKAGE(OpenGL) # header list SET(LIB_HDRS mainwindow.h ) # module list SET(LIB_SRCS mainwindow.cpp ) # moc QT4_WRAP_CPP(MOC_OUTFILES ${LIB_HDRS}) # library SET(LIB_NAME ${PROJECT_NAME}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_LIBRARY(${LIB_NAME} ${LIB_SRCS} ${LIB_HDRS} ${MOC_OUTFILES}) # executable ADD_EXECUTABLE(${APPNAME} MACOSX_BUNDLE main.cpp) TARGET_LINK_LIBRARIES(${APPNAME} ${LIB_NAME} ${QT_LIBRARIES} ${OPENGL_LIBRARIES} ) # install target INSTALL( TARGETS ${APPNAME} RUNTIME DESTINATION bin BUNDLE DESTINATION /Applications )
Once we compiled the Qt application with
cmake . && make
we install the application with
sudo make install
This creates an application bundle in /Applications on MacOS X or installs the application in /usr/local/bin on Unix.
Besides traditonal development with the shell, compiler and source code editor, the the following integrated development environments are recommended:
- QtCreator
- KDevelop
- Eclipse
Most modern IDEs have integrated support for CMake. To start development with a CMake based project, just import the CMake project (CMakeLists.txt) into a project of the respective IDE such as QtCreator.
← Qt Painter Example | ● | Qt with DCMTK →