Make graphs in C++ with Qwt and Visual Studio

  • Post category:C++ / Qt
  • Post comments:0 Comments

If you want to make graphs in C++ with Qt, you have a few solutions. Qt Charts and QCustomPlot are great ones if GPL license is not a problem. On the contrary, it is also possible to draw everything from scratch in a Graphics Widget, or use Qwt. In this article, we are gonna take a look at how to build Qwt on Windows with Visual Studio 2019.

Get Qwt

At the time of writing this post, the last version of Qwt is 6.1.5, it is available here :
https://sourceforge.net/projects/qwt/files/

The build shown here is made with Qt 5.15 and Visual Studio Community 2019.

Build Qwt

In order to build this library, we can use qmake int the command line interface, or with Qt Creator. The last has the advantage of automatically creating folders for different versions, 32 or 64 bits, so we’ll use it.

Start by opening the qwt.pro file with Qt Creator, and configure it with MSVC 2019.

Configuring qwt with Qt Creator

Next, select the desired kit.

then execute qmake (menu Build -> run qmake) for both kits. This creates a folder for every wanted architecture.

In every folder created, we’ll have to run nmake. To do this, open the folder in cmd (it’s possible to do it by shift + right clicking in the folder to run powershell here, and type cmd). For all the environment variables to be correctly prepared, before running nmake, run a script in visual studios folder :

C:Program Files (x86)Microsoft Visual Studio2019CommunityVCAuxiliaryBuildvcvars64.bat

This is the 64 bits version, you have to choose the correct on depending on the version you want to build. To run it, just drag and drop it in the cmd window, the execution confirms the chosen architecture.

From here just run the commands “nmake” and “nmake install”.
The library files are installed in this folder : C:/Qwt-6.1.5 by default. You can create x86 and x64 folders to store the generated dll files if you want to have both versions, and do it all again for the other architecture.

Use Qwt

We now have qwt build for visual studio 2019. Props files can be created to include the library more easily in future projects. qwt_designer_plugin.dll can be placed in Qt designer plugins folder to access graphs directly from it.
Now we can start a simple Qt project and display a simple graph.

Qwt test from visual studio 2019

Here is the compiled lib for Visual studio 2019 and Qt 5.15 if you want to use it :