[vtk-developers] VTK and determining the Qt version.
Andrew Maclean
andrew.amaclean at gmail.com
Mon Oct 14 02:43:07 EDT 2013
Continuing on with this, here is a CMakeLists.txt file for GraphicsView
that demonstrates how to use VTK_QT_VERSION. In this case, note line 25
where it is manually set. I assume it still works with Qt4, it certainly
now works with Qt5!
One other thing I had to do was to change:
QGraphicsItem* item = itemAt(e->scenePos());
to:
QGraphicsItem* item = itemAt(e->scenePos(),QTransform());
in OpenGLScene.cpp
So if we could set a global configuration option in VTKConfig.cmake for
VTK_QT_VERSION then this would certainly work.
Regards
Andrew
On Mon, Oct 14, 2013 at 3:27 PM, Andrew Maclean
<andrew.amaclean at gmail.com>wrote:
> This has arisen because I was looking at the Qt examples in VTK in the
> folder Examples/GUI/Qt and thinking about issues that might arise when
> building them as standalone examples.
>
> If they are built within VTK, then a similar approach can be used to that
> used when the VTK Qt tests are built,namely by adding the following code
> like this in their respective CMakeLists.txt files:
>
> --------------------------------------------------------------------------
> if(VTK_QT_VERSION VERSION_GREATER "4")
> # Do something specific for Qt5
> else()
> # Do something specific for Qt4
> endif()
> --------------------------------------------------------------------------
>
> Now the problem is that VTK_QT_VERSION is not a global configuration
> setting. So we don't know what version of Qt was used when VTK was built.
> This means that when building examples we have no way (as far as I can see)
> of determining what version of Qt was used.
>
> My initial thinking is that we need to have a global configuration option
> in VTKConfig.cmake, like this:
> SET(VTK_QT_VERSION "5") or SET(VTK_QT_VERSION "4") depending upon the Qt
> version.
>
> Then in your CMake code have:
> if(VTK_QT_VERSION VERSION_GREATER "4")
> # Do something specific for Qt5
> else()
> # Do something specific for Qt4
> endif()
>
> I think this would work, but has anyone else a better idea or solution?
>
> In case you think it is a trivial problem, at present I can't build the
> Wiki Examples because they assume Qt4 is used.
>
>
> Thanks
> Andrew
>
>
> --
> ___________________________________________
> Andrew J. P. Maclean
>
> ___________________________________________
>
--
___________________________________________
Andrew J. P. Maclean
___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20131014/839fb4d2/attachment.html>
-------------- next part --------------
#-----------------------------------------------------------------------------
project( GraphicsView )
cmake_minimum_required(VERSION 2.8.8)
#-----------------------------------------------------------------------------
# Eliminate a warning when building in Windows that relates
# to static linking of Qt executables to qtmain.lib.
# This policy was introduced in CMake version 2.8.11.
# CMake version 2.8.11.2 warns when the policy is not set
# and uses OLD behavior.
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif()
#-----------------------------------------------------------------------------
# We will enforce an out of source build.
string(COMPARE EQUAL "${${PROJECT_NAME}_SOURCE_DIR}"
"${${PROJECT_NAME}_BINARY_DIR}" INSOURCE)
if(INSOURCE)
message(FATAL_ERROR "${PROJECT_NAME} requires an out of source build. Please create a separate binary directory and run CMake there.")
endif(INSOURCE)
set(VTK_QT_VERSION "5")
if(VTK_QT_VERSION VERSION_LESS "5")
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL 1)
set(QT_USE_QTWEBKIT 1)
include(${QT_USE_FILE})
else()
find_package(Qt5WebKitWidgets REQUIRED QUIET)
include_directories(${Qt5WebKitWidgets_INCLUDE_DIRS})
add_definitions(${Qt5WebKitWidgets_DEFINITIONS})
set(QT_LIBRARIES ${Qt5WebKitWidgets_LIBRARIES})
endif()
find_package(OpenGL)
if(NOT VTK_BINARY_DIR)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
endif()
if(VTK_QT_VERSION VERSION_LESS "5")
if (NOT QT_QTWEBKIT_FOUND OR QT_VERSION_MINOR LESS 6)
message(STATUS "VTK isn't configured to use QtOpenGL, QtWebKit wasn't found, or Qt 4.6 wasn't found. GraphicsView example is disabled.")
else()
qt4_add_resources(qrcfiles GraphicsView.qrc)
qt4_wrap_cpp(mocs
OpenGLScene.hpp
QBoolAnimation.h
WebView.h
)
add_executable(qtgraphicsview
main.cpp
OpenGLScene.cpp
TreeRingViewItem.cpp
GraphLayoutViewItem.cpp
WebView.cpp
${mocs}
${qrcfiles}
)
target_link_libraries(qtgraphicsview ${QT_LIBRARIES} ${VTK_LIBRARIES})
endif()
else()
set( Srcs
main.cpp
OpenGLScene.cpp
TreeRingViewItem.cpp
GraphLayoutViewItem.cpp
WebView.cpp
)
set( Incs
GraphicsView.hpp
OpenGLScene.hpp
QBoolAnimation.h
TreeRingViewItem.h
GraphLayoutViewItem.h
WebView.h
)
set( MOC_Hdrs
OpenGLScene.hpp
QBoolAnimation.h
WebView.h
)
# This command will generate rules that will run rcc on all files from RCS
# the RC_Srcs variable will contain paths to files produced by rcc
qt5_add_resources(RC_Srcs GraphicsView.qrc )
#-----------------------------------------------------------------------------
# Create code from a list of Qt designer ui files.
#qt5_wrap_ui(UI_Hdrs ${UIS})
qt5_wrap_cpp(MOC_Srcs ${MOC_Hdrs})
# If you are using WIN32, a console will also be built.
# Useful for debugging in that you can write to it.
add_executable(qtgraphicsview MACOSX_BUNDLE ${Srcs} ${Incs} ${MOC_Srcs} ${RC_Srcs} ${UI_Hdrs})
qt5_use_modules(qtgraphicsview Core Gui Widgets WebKit WebKitWidgets OpenGL OpenGLExtensions)
target_link_libraries(qtgraphicsview ${VTK_LIBRARIES})
endif()
More information about the vtk-developers
mailing list