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
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.
- Plugin Installation
- Plugin Configuration
- Using the plugin
- Common Problems
- 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).
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:
The Qt Creator source code can be built within your existing Qt Creator installation. Simply:
- Extract the downloaded archive.
- Open the qtcreator.pro file in your existing Qt Creator Installation.
- Ensure the project is triggered for Release.
- 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 in single URL format, as above.
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:
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:
- Show local issues only.
- Show issues in current file only.
- Change selected issue status.
- Filter issues by status.
Please contact our global support team if you have a feature request, bug report or need any assistance with the plugin: [email protected]
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.