Skip to content

Commit 384636e

Browse files
committed
COMP 12945: Allow VTK to build against Qt5
Since VTK build system has been updated to make use of CMake macros specific to Qt5, the support has to explicitly enabled configuring VTK with -DVTK_QT_VERSION:STRING="5" Additionally, in case Qt5 is not installed in a standard location, a custom prefix for "find_package" should be passed. For example: -DCMAKE_PREFIX_PATH:STRING=/home/jchris/Qt5.0.2/5.0.2/gcc_64/ Finally, this commit also resolves the build errors reported below. Fix missing header build error by including Qt headers directly without specifying the intermediate directory. * Fix build error changing QString::toAscii into QString::toLatin The method "toAscii" has been deprecated and is not available in default Qt5 distribution. See http://qt-project.org/doc/qt-5.0/qtcore/qstring.html#toAscii * Fix build error changing Qt::WFlags into Qt::WindowFlags See http://qt-project.org/doc/qt-5.0/qtcore/qt-obsolete.html * Fix build error changing QAbstractItemModel::reset() into combo QAbstractItemModel::beginResetModel()/QAbstractItemModel::endResetModel() The method "reset" has been deprecated and is not available in default Qt5 distribution. See http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel-compat.html#reset * Fix build error by including "vtkObjectBase.h": /home/jchris/Projects/Qt5.0.2/5.0.2/gcc_64/include/QtCore/qmetatype.h:464: error: invalid application of ‘sizeof’ to incomplete type ‘QStaticAssertFailure<false>’ * Fix "no matching function for call to ‘QPixmap::grabWidget(QWidget*)’" by using "QWidget::grab" See http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#grab * Fix missing QHttpHeader/QHttpRequestHeader headers by removing them. They have been removed from Qt5 and were not used in the code. * Fix error: ‘qInstallMsgHandler’ was not declared in this scope by using "qInstallMessageHandler" See http://qt-project.org/doc/qt-5.0/qtdoc/sourcebreaks.html * Fix Q4VTKWidgetPlugin.cxx:147: error: invalid application of ‘sizeof’ to incomplete type ‘QStaticAssertFailure<false>’ by using "Q_PLUGIN_METADATA" macro instead of Q_EXPORT_PLUGIN or Q_EXPORT_PLUGIN2. See http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5#7ec1b8f08d7f31ebcb53188f0bd15ed5 Change-Id: Ie7123e5990e3a8afb4d7d2efa0fda5bd7b98c1e3
1 parent 20539fb commit 384636e

28 files changed

+239
-86
lines changed

CMake/vtkQt.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(VTK_QT_VERSION "4" CACHE STRING "Expected Qt version")
2+
mark_as_advanced(VTK_QT_VERSION)
3+
4+
set_property(CACHE VTK_QT_VERSION PROPERTY STRINGS 4 5)
5+
6+
if(NOT (VTK_QT_VERSION VERSION_EQUAL "4" OR VTK_QT_VERSION VERSION_EQUAL "5"))
7+
message(FATAL_ERROR "Expected value for VTK_QT_VERSION is either '4' or '5'")
8+
endif()

Examples/GUI/Qt/GraphicsView/CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11

2-
find_package(Qt4 REQUIRED)
3-
set(QT_USE_QTOPENGL 1)
4-
set(QT_USE_QTWEBKIT 1)
5-
include(${QT_USE_FILE})
2+
if(NOT VTK_USE_QT5)
3+
find_package(Qt4 REQUIRED)
4+
set(QT_USE_QTOPENGL 1)
5+
set(QT_USE_QTWEBKIT 1)
6+
include(${QT_USE_FILE})
7+
else()
8+
find_package(Qt5WebKitWidgets REQUIRED QUIET)
9+
include_directories(${Qt5WebKitWidgets_INCLUDE_DIRS})
10+
add_definitions(${Qt5WebKitWidgets_DEFINITIONS})
11+
set(QT_LIBRARIES ${Qt5WebKitWidgets_LIBRARIES})
12+
endif()
613

714
find_package(OpenGL)
815

Examples/Infovis/Cxx/CustomLinkView/CustomLinkView.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void CustomLinkView::slotOpenXMLFile()
161161
}
162162

163163
// Create XML reader
164-
this->XMLReader->SetFileName( fileName.toAscii() );
164+
this->XMLReader->SetFileName( fileName.toLatin1() );
165165
this->XMLReader->ReadTagNameOff();
166166
this->XMLReader->Update();
167167

Examples/Infovis/Cxx/EasyView/EasyView.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void EasyView::slotOpenXMLFile()
131131
}
132132

133133
// Create XML reader
134-
this->XMLReader->SetFileName( fileName.toAscii() );
134+
this->XMLReader->SetFileName( fileName.toLatin1() );
135135
this->XMLReader->ReadTagNameOff();
136136
this->XMLReader->Update();
137137

Examples/Infovis/Cxx/StatsView/StatsView.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void StatsView::slotOpenSQLiteDB()
9494

9595
// Create SQLite reader
9696
QString fullName = "sqlite://" + fileName;
97-
vtkSQLiteDatabase* db = vtkSQLiteDatabase::SafeDownCast( vtkSQLDatabase::CreateFromURL( fullName.toAscii() ) );
97+
vtkSQLiteDatabase* db = vtkSQLiteDatabase::SafeDownCast( vtkSQLDatabase::CreateFromURL( fullName.toLatin1() ) );
9898
bool status = db->Open("");
9999
if ( ! status )
100100
{

GUISupport/Qt/CMakeLists.txt

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(vtkQt)
2+
13
# set up sources to build
24
set(QVTKLibSrcs
35
vtkEventQtSlotConnect.cxx
@@ -52,13 +54,23 @@ set(QVTKNonMocHeaders
5254
QVTKInteractor.h
5355
)
5456

55-
# import Qt4 build settings
56-
set(QT_USE_QTNETWORK 1)
57-
find_package(Qt4 REQUIRED QUIET)
58-
mark_as_advanced(QT_QMAKE_EXECUTABLE)
59-
include(${QT_USE_FILE})
57+
if(VTK_QT_VERSION VERSION_GREATER "4")
58+
find_package(Qt5Widgets REQUIRED QUIET)
59+
include_directories(${Qt5Widgets_INCLUDE_DIRS})
60+
add_definitions(${Qt5Widgets_DEFINITIONS})
61+
62+
qt5_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
63+
64+
set(QT_LIBRARIES ${Qt5Widgets_LIBRARIES})
65+
else()
66+
# import Qt4 build settings
67+
set(QT_USE_QTNETWORK 1)
68+
find_package(Qt4 REQUIRED QUIET)
69+
mark_as_advanced(QT_QMAKE_EXECUTABLE)
70+
include(${QT_USE_FILE})
6071

61-
qt4_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
72+
qt4_wrap_cpp(QVTKLibMocSrcs ${QVTKMocHeaders})
73+
endif()
6274

6375
foreach(opt
6476
QT_RCC_EXECUTABLE
@@ -94,9 +106,18 @@ if(BUILD_SHARED_LIBS)
94106

95107
set(PluginMocHeaders Q4VTKWidgetPlugin.h)
96108

97-
add_definitions(-DQT_PLUGIN)
98-
include_directories(${QT_QTDESIGNER_INCLUDE_DIR})
99-
qt4_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
109+
if(VTK_QT_VERSION VERSION_GREATER "4")
110+
find_package(Qt5Designer REQUIRED QUIET)
111+
add_definitions(${Qt5Designer_DEFINITIONS})
112+
include_directories(${Qt5Designer_INCLUDE_DIRS})
113+
qt5_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
114+
set(QT_LIBRARIES ${Qt5Designer_LIBRARIES})
115+
else()
116+
add_definitions(-DQT_PLUGIN)
117+
include_directories(${QT_QTDESIGNER_INCLUDE_DIR})
118+
qt4_wrap_cpp(PluginMocSrcs ${PluginMocHeaders})
119+
set(QT_LIBRARIES ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY})
120+
endif()
100121

101122
# add QVTK plugin from sources
102123
# stand-alone as it doesn't depend on QVTK library
@@ -109,10 +130,7 @@ if(BUILD_SHARED_LIBS)
109130
set_target_properties(QVTKWidgetPlugin PROPERTIES COMPILE_DEFINITIONS QT_NO_DEBUG)
110131

111132
# link with Qt libs
112-
target_link_libraries(QVTKWidgetPlugin
113-
${QT_QTGUI_LIBRARY}
114-
${QT_QTCORE_LIBRARY}
115-
)
133+
target_link_libraries(QVTKWidgetPlugin ${QT_LIBRARIES})
116134

117135
# install rules
118136

GUISupport/Qt/Q4VTKWidgetPlugin.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,7 @@ QList<QDesignerCustomWidgetInterface*> QVTKPlugin::customWidgets() const
144144
return plugins;
145145
}
146146

147+
#if QT_VERSION < 0x050000
147148
Q_EXPORT_PLUGIN(QVTKPlugin)
149+
#endif
148150

GUISupport/Qt/Q4VTKWidgetPlugin.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727

2828
#include <QDesignerCustomWidgetInterface>
2929
#include <QDesignerCustomWidgetCollectionInterface>
30-
#include <QtPlugin>
3130
#include <QObject>
31+
#if QT_VERSION >= 0x050000
32+
# include <QtDesigner>
33+
#endif
34+
#include <QtPlugin>
3235
#include <QWidget>
3336

3437

@@ -54,10 +57,13 @@ class QVTKWidgetPlugin : public QDesignerCustomWidgetInterface
5457
class QVTKPlugin : public QObject, public QDesignerCustomWidgetCollectionInterface
5558
{
5659
Q_OBJECT
60+
#if QT_VERSION >= 0x050000
61+
Q_PLUGIN_METADATA(IID "org.vtk.qvtkplugin")
62+
#endif
5763
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
5864
public:
5965
QVTKPlugin();
60-
~QVTKPlugin();
66+
virtual ~QVTKPlugin();
6167

6268
virtual QList<QDesignerCustomWidgetInterface*> customWidgets() const;
6369
private:

GUISupport/Qt/QVTKWidget.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
#endif
7575

7676
/*! constructor */
77-
QVTKWidget::QVTKWidget(QWidget* p, Qt::WFlags f)
77+
QVTKWidget::QVTKWidget(QWidget* p, Qt::WindowFlags f)
7878
: QWidget(p, f | Qt::MSWindowsOwnDC), mRenWin(NULL),
7979
cachedImageCleanFlag(false),
8080
automaticImageCache(false), maxImageCacheRenderRate(1.0),
@@ -401,7 +401,7 @@ bool QVTKWidget::event(QEvent* e)
401401

402402
if(QObject::event(e))
403403
{
404-
return TRUE;
404+
return true;
405405
}
406406

407407
if(e->type() == QEvent::KeyPress)

GUISupport/Qt/QVTKWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
#include "vtkGUISupportQtModule.h" // For export macro
4040
#include "QVTKInteractor.h"
41-
#include <QtGui/QWidget>
41+
#include <QWidget>
4242

4343
class QVTKInteractorAdapter;
4444

@@ -85,7 +85,7 @@ class VTKGUISUPPORTQT_EXPORT QVTKWidget : public QWidget
8585

8686
public:
8787
//! constructor
88-
QVTKWidget(QWidget* parent = NULL, Qt::WFlags f = 0);
88+
QVTKWidget(QWidget* parent = NULL, Qt::WindowFlags f = 0);
8989
//! destructor
9090
virtual ~QVTKWidget();
9191

0 commit comments

Comments
 (0)