How to use PCL with Qt GUI

What is Qt?

Qt is a cross-platform application development frameworks for C++.
You can create applications that operate in multi environments without rewriting the source code that use functions such as GUI, Networks.

PCL with Qt GUI

The tutorial for using PCL with Qt has published in official site.
You can create rich GUI application by using Qt.

How to Build Tutorial?

However, This tutorial doesn’t work on the latest environments.
I will publish that how to build this sample program using the latest development environments.

Development Environment

I confirmed it on the following development environments.

  • Visual Studio 2015
  • PCL 1.8.0
  • VTK 7.1.0
  • Qt 5.8.0
  • CMake 3.6.1 (or later)

Build VTK with Qt (QVTK) and Generate QVTKWidgetPlugin

The VTK with Qt functions enabled is required for PCL with Qt.
In general, This is called QVTK.

You need install Qt and build QVTK.
And, You need generate QVTKWidgetPlugin and register to Qt Designer.
Please refer to following document.

Build PCL with QVTK

Then, You need build PCL using QVTK that created above step.
Please refer to following document.

At this step, set QVTK path to VTK_DIR, and check WITH_QT option in CMake congfiguration.
Incidentally, You can use 3rd-Party libraries (Boost, Eigen, FLANN, QHull, OpenNI2) other than VTK that included in PCL All-in-one Installer.

Build Sample Program

Next, You will build sample program of tutorial.

1. Fix Sample Program

You can download sample program from PCL repository.
But, This source program is written for the old environments (Qt4).
You need fix this source program.

You can download sample program that has been fixed from the following.

The fix is as follows.
All CMakeLists.txt has been re-written.
Qt Creators project file has re-written Qt major version to 5.

  • CMakeLists.txt#ALL
  • 	cmake_minimum_required( VERSION 3.6 )
    	# Create Project
    	project( pcl_visualizer )
    	# Set StartUp Project
    	set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "pcl_visualizer" )
    	# Find PCL Package
    	set( PCL_ROOT $ENV{PCL_ROOT} )
    	find_package( PCL 1.8.0 REQUIRED )
    	# Find VTK Package
    	# VTK_DIR is QVTK directory
    	set( VTK_DIR "$ENV{PCL_ROOT}/3rdParty/VTK" )
    	find_package( VTK REQUIRED )
    	# Find Qt Package
    	# QTDIR is Qt directory
    	set( QTDIR $ENV{QTDIR} )
    	find_package( Qt5Widgets REQUIRED )
    	# Set Automatic MOC
    	set( CMAKE_AUTOMOC ON )
    	# Generate MOC Code and UI Header
    	qt5_wrap_cpp( MOC pclviewer.h )
    	qt5_wrap_ui( UI_HEADER pclviewer.ui )
    	# Add Executable
    	add_executable( pcl_visualizer main.cpp pclviewer.h pclviewer.cpp pclviewer.ui )
    	# Additional Include Directories
    	include_directories( ${PCL_INCLUDE_DIRS} )
    	include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
    	include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
    	# Load VTK Settings
    	include( ${VTK_USE_FILE} )
    	# Preprocessor Definitions
    	add_definitions( ${PCL_DEFINITIONS} )
    	# Additional Library Directories
    	link_directories( ${PCL_LIBRARY_DIRS} )
    	# Additional Dependencies
    	target_link_libraries( pcl_visualizer ${PCL_LIBRARIES} ${VTK_LIBRARIES} Qt5::Widgets )
  • 	greaterThan(QT_MAJOR_VERSION, 5): QT += widgets

2. Open Qt Creator Project

Launch Qt Creator and open the project file (qt_visualizer/sample/src/
Press [Configure Project] button.

Configure Project

3. Build Settings

Press [Projects] button to open the Build Settings.
You need setting as follows.

3-1. Edit Build Configuration

Select the build configuration (Debug or Release) from the pull-down menu in “Edit build configuration”.

3-2. Set Build Directory

Specify build directory (../build) in “General” > “Build directory”.
This build directory must be at the same depth as the source code directory.
It is specification of Qt Creator.

   ├── CMakeLists.txt
   ├── main.cpp
   ├── pclviewer.cpp
   ├── pclviewer.h
   ├── pclviewer.ui
3-3. Set Build Steps

Set build steps to “Build Steps”.
First, delete all existing build steps.

Add two “Custom Process Step” from pull down menu.
The 1st build step is CMake commands to create project.
The 2nd build step is MSBuild commands to build project.


Command cmake
Arguments -G “Visual Studio 14 2015 Win64” ../src
(or -G “Visual Studio 14 2015” ../src)
Working directory %{buildDir}/../build

Command msbuild
Arguments pcl_visualizer.vcxproj /p:configuration=release
(or pcl_visualizer.vcxproj /p:configuration=debug)
Working directory %{buildDir}/../build

Build Steps for Debug
Build Steps for Release

4. Build Project

Select build configuration (Debug or Release).
Then, Build project by pressing [Build Project] button.

Edit Build Configuration
Build Project

5. Execution

Press [Run] button to execute sample program.
It is displayed as follows.

Run Sample Program

5 thoughts on “How to use PCL with Qt GUI”

  1. Thank you so much Sugiura!
    I was trying to compile this example for more or less two weeks. Yesterday, I found your tutorial and finally it is working.

  2. Hello Tsukasa,
    Thank you very much.
    I have followed your tutorials about build PCL 1.8.0 with source code (I need PCAP), and it works really well. Now I want to add QT to PCL. My question is about the version of VTK: I use VTK 7.0.0, is it necessary to use VTK 7.1.0, or VTK 7.0.0 is OK? And how to do if I need to change the version of VTK for PCL with QT.
    Thank you!

  3. I was wondering how you would do it from scratch ( without cloning from the repo).
    Some questions I had:
    1. Where is the .pro file coming from?
    2. Should I create a new project from Qt creator and then make my directories and CMakeLists.txt?
    3. Or can I create a project with all my directories and CMakeLists.txt and then import it to Qt Creator?

    1. Hi Jay,

      I don’t know how to create a new project to use PCL using Qt Creator.
      I recommend you start develop based on sample project.
      If you want more information, I recommend you post to users forum or Qt forum.

      Q1. Where is the .pro file coming from?
      A1. It is project file of Qt Crteator. It is generated when creating a project using Qt Creator.

      Q2. Should I create a new project from Qt creator and then make my directories and CMakeLists.txt?
      A2. I don’t know, because I have never done it.

      Q3. Or can I create a project with all my directories and CMakeLists.txt and then import it to Qt Creator?
      A3. I don’t know, because I have never done it.

Leave a Reply

Your email address will not be published. Required fields are marked *