We recently announced the Klocwork QT Creator Plugin, which you can read more about here. Along with this, we wanted to make it as easy as possible to install and use the plugin, and have released the following documentation to help get you set up.

Klocwork QT Creator Plugin

 

Klocwork: Introducing the Klocwork QT Creator PluginEmenda’s Klocwork Plugin for QT Creator provides an easy way for Klocwork users to use the Klocwork static code analyser within their QT Creator IDE, providing a seamless analysis experience.

QT Creator: Introducing the Klocwork QT Creator Plugin

The plugin provides several simple interface windows within QT Creator to configure Klocwork settings, view Klocwork issues and filter issues by various metrics. By automating the analysis process during the development stage, the plugin does all the heavy lifting so that you can focus on delivering higher quality code faster, all within the QT Creator IDE.

 


Contents

  1. Features
  2. Prerequisites
  3. Plugin Installation
  4. Plugin Configuration
  5. Using the plugin
  6. Support
  7. Common Problems

1. Features

  • Perform “on-the-fly” (instant) Klocwork analyses of your code within Qt Creator.
  • Support for multiple Klocwork versions (v9.6, v10.x, v11.x, v12.x).
  • Uses existing Klocwork installations and licenses.
  • Synchronise your local Klocwork project with a Klocwork server project.
  • Change Klocwork issue status’.
  • Filter Klocwork issues by status.
  • Show only local Klocwork issues.
  • Show Klocwork issues only present in the currently opened file.
  • Create custom kwcheck commands for personalised analyses (new).

2. Prerequisites

In general, when writing these instructions we have assumed a basic knowledge of Klocwork and Qt Creator.

2.1. QT and QT Creator Version

The Emenda Klocwork QT Creator plugin has been developed in compatibility with:

QT version: 5.9.3
QT Creator version: 4.4.1

Recent QT and QT Creator developments have deprecated some functions used by older versions of the Emenda Klocwork QT Creator plugin. As such, if you are using an older version of either of these, we advise you to download the plugin source from our Github repository here instead.

2.2. Klocwork Version

Klocwork version 9.6 or newer.

2.3. Klocwork Command Line Tools

Similarly to our other IDE plugins, the Klocwork QT Creator plugin uses Klocwork’s command line tools to run analyses in the background. You can download the command line tools for your specific Klocwork version from Roguewave’s Support Website, or from your local Klocwork partner.

2.4. Klocwork Local Project Setup

In order for the plugin to effectively analyse your code, you must first generate a build specification file and then set up a local Klocwork project (a repository for your analysis results and settings). The plugin then uses this information to perform its analysis of your code automatically.

You can find the Eclipse IDE instructions here, which are similar.


3. Plugin Installation

3.1. Build the QT Creator Source Code

To build the plugin, you must first build QT Creator’s source code. Building this provides the required libraries for the QT Creator version in use during the build of the plugin. In order to do this, first download the source for your desired QT Creator version, which should match the version of QT Creator you are using for your development, from the official QT repository:

https://download.qt.io/official_releases/qtcreator/

The QT Creator source code can be built within your existing QT Creator installation. Simply:

  1. Extract the downloaded archive.
  2. Open the qtcreator.pro file in your existing QT Creator Installation.
  3. Ensure the project is triggered for Release.
  4. Build the project.

3.2. Build the Klocwork QT Creator Plugin

In order to build the plugin, you must download the plugin source code, which you can find on GitLab here, and configure a few important settings.

Load the klocwork.pro file into your existing QT Creator installation, then adjust the following two variables to point to the source code and libraries built in step 3.1:

  • QTCREATOR_SOURCES       Where the source code for QT Creator resides, e.g. /home/QT/qtcreator-opensource/src
  • IDE_BUILD_TREE                   Where QT built the QT Creator source code, e.g. /home/QT/build-qtcreator-opensource-Release

Once the changes have been made to the klocwork.pro file, configure the project for release and then build the plugin.

The build generates a library klocwork.* with the library file extension based on the compiler used (e.g. klocwork.lib). This file is located in the build directory of the QT Creator source code.
e.g. /home/QT/ build-qtcreator-opensource-Release/lib/qtcreator/plugins

The plugin library file can be copied and deployed into the libs directory of your own QT Creator installation.

5. Plugin Configuration

Now that you have installed the plugin, you should have access to several new windows within QT Creator. Firstly, the Klocwork project settings menu shown below:

In this window, specify the full path to the build specification file generated during step 2.4. You should also specify your Klocwork server hostname and port, as well as the Klocwork server project that you want to synchronise with.

Secondly, you should see the the Klocwork Options menu, which can be accessed within the “Analyzer” section of QT Creator’s options as seen below:

qt creator

In this window, specify the full path to the local analysis tool kwcheck, installed during the satisfaction of prerequisite 2.3. You must also specify your Klocwork License hostname and port, as well as any custom local analysis metrics you wish to use.

5. Using the plugin

Now that you have the plugin installed, as well as a local Klocwork project set up, you can get perform your first Klocwork analysis within QT Creator. Below, we demonstrate how to do so using the “garage-local” project.

First, import the project into QT Creator, noting that the location should match the project created in step 2.4:

Once this has been done, you should be able to use the Klocwork analysis tools to analyse your files. Simply open a source file within QT Creator and then select Tools -> Klocwork -> Analyse Current File.

Klocwork will then run a local analysis in the background and provide issue information once the analysis is complete:

The issue flags illustrate where in the source code issues are present, and double clicking on a issue within the Klocwork Issues list takes you to the issue’s respective flag.

Just above the issue list is the Klocwork filtering options. From left to right, these four options provide you with the ability to:

  1. Show local issues only.
  2. Show issues in current file only.
  3. Change selected issue status.
  4. Filter issues by status.

 

6. Support

Please contact our global support team if you have a feature request, bug report or need any assistance with the plugin: support@emenda.eu

7. Common Problems

7.1. Project ERROR: Unknown module(s) in QT: script

The QTScript module was deprecated in QT versions 5.5 and onwards, but is depended on by QT Creator to build. If you have installed Qt through the online installer, then there is a separate optional “Qt script (deprecated)” package available that downloads and installs the library.