Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Migration CMake projects from Qt4 to Qt5

$
0
0
As the QtCreator 2.7, I created a simple project “Migration” based on CMake. I want to get Qt4/5 compatible file of the project. I already have a prototype that I tested with Qt4/5 on Windows and Linux. And it works on this little example. But I want to get the comments to make the code better. The project now consists of three files. CMakeLists.txt: project(Migration)   cmake_minimum_required(VERSION 2.8.9)   list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})   aux_source_directory(. SRC_LIST) add_executable(${PROJECT_NAME} ${SRC_LIST})   include(QtMigration)   QT_USE_MODULES(${PROJECT_NAME} Core Gui) QtMigration.cmake: cmake_minimum_required(VERSION 2.8.9)   macro(QT_USE_MODULES _target)     # Enable AUTOMOC     set_target_properties(${_target} PROPERTIES AUTOMOC TRUE)     # Local variables     set(_modules_qt4)     set(_modules_qt5)     # Prepare modules     foreach(_module ${ARGN})         list(APPEND _modules_qt4 Qt${_module})         list(APPEND _modules_qt5 ${_module})         if(_module MATCHES "Gui")             list(APPEND _modules_qt5 "Widgets")         endif(_module MATCHES "Gui")     endforeach(_module ${ARGN})     list(REMOVE_DUPLICATES _modules_qt4)     list(REMOVE_DUPLICATES _modules_qt5)     # Find Qt libraries     find_package(Qt5 QUIET COMPONENTS ${_modules_qt5})     if(Qt5_FOUND)         qt5_use_modules(${_target} ${_modules_qt5})     else(Qt5_FOUND)         find_package(Qt4 QUIET COMPONENTS ${_modules_qt4})         if(Qt4_FOUND OR QT4_FOUND)             include(${QT_USE_FILE})             include_directories(${QT_INCLUDES})             add_definitions(${QT_DEFINITIONS})             target_link_libraries(${_target} ${QT_LIBRARIES})         endif(Qt4_FOUND OR QT4_FOUND)     endif(Qt5_FOUND) endmacro(QT_USE_MODULES) And main.cpp: #include <QApplication> #include <QLabel>   int main(int argc, char *argv[]) {     QApplication app(argc, argv);       QLabel label(QString("Hello Qt%1!").arg(int(QT_VERSION >> 16)));     label.setAlignment(Qt::AlignCenter);     label.resize(200, 100);     label.show();       return app.exec(); }

Viewing all articles
Browse latest Browse all 18427

Trending Articles