QCustomPlot Discussion and Comments

Issues Enabling OpenGL Support with CMakeReturn to overview

Hello,

I'm currently trying to enable OpenGL support for QCustomPlot in my project using CMake, but I am running into an issue.

Here is what I have tried so far:

add_definitions(-DQCUSTOMPLOT_USE_OPENGL)
target_add_definitions(my_program PRIVATE QCUSTOMPLOT_USE_OPENGL)
find_package(OpenGL REQUIRED)
target_link_libraries(my_program Qt5::Widgets QCustomPlot OpenGL::GL)

However, after building the project, the QCustomPlot graphs still do not use OpenGL for rendering, and I am still encountering the following error:

void QCustomPlot::setOpenGl(bool, int) QCustomPlot can't use OpenGL because QCUSTOMPLOT_USE_OPENGL was not defined during compilation (add 'DEFINES += QCUSTOMPLOT_USE_OPENGL' to your qmake .pro file)

Is it even possible to use OpenGL support with QCustomPlot when building with CMake, or is it only supported in qmake?

It should work, I use OpenGL with Meson: https://github.com/jeandet/QCustomPlot/blob/v2.1.1-meson/meson.build#L130 . I wonder if you didn't forget to enable OpenGL while building QCP itself, from your snippet it looks like you only set QCUSTOMPLOT_USE_OPENGL while building your app.

Oh! Indeed, I was compiling my application with this flag, not the library. I didn’t realize at first that the library itself needed to be compiled with it.

Compiling the library worked. Thank you!