QCustomPlot Discussion and Comments

QT 6.2 patchReturn to overview

if anyone needs this is the patch to make QCustomPlot 2.1 amalgamated (from download page) compile with QT 6.2

your old trick doesnt work anymore in the qt 6.2, so ifdef this version with the one you have.
this works with QT 5.8+

Only in qcustomplot: changelog.txt
Only in qcustomplot: documentation
Only in qcustomplot: examples
Only in qcustomplot: GPL.txt
diff -u qcustomplot/unpatched/qcustomplot.h qcustomplot/qcustomplot.h
--- qcustomplot/unpatched/qcustomplot.h	2021-09-07 22:38:29.333639801 +0200
+++ qcustomplot/qcustomplot.h	2021-10-03 17:30:21.411847294 +0200
@@ -156,26 +156,8 @@
   It provides QMetaObject-based reflection of its enums and flags via \a QCP::staticMetaObject.
-#ifndef Q_MOC_RUN
 namespace QCP {
-class QCP { // when in moc-run, make it look like a class, so we get Q_GADGET, Q_ENUMS/Q_FLAGS features in namespace
-  Q_ENUMS(ExportPen)
-  Q_ENUMS(ResolutionUnit)
-  Q_ENUMS(SignDomain)
-  Q_ENUMS(MarginSide)
-  Q_FLAGS(MarginSides)
-  Q_ENUMS(AntialiasedElement)
-  Q_FLAGS(AntialiasedElements)
-  Q_ENUMS(PlottingHint)
-  Q_FLAGS(PlottingHints)
-  Q_ENUMS(Interaction)
-  Q_FLAGS(Interactions)
-  Q_ENUMS(SelectionRectMode)
-  Q_ENUMS(SelectionType)
   Defines the different units in which the image resolution can be specified in the export
@@ -318,6 +300,20 @@
                      ,stMultipleDataRanges ///< Any combination of data points/ranges can be selected
+  Q_ENUM_NS(ExportPen)
+  Q_ENUM_NS(ResolutionUnit)
+  Q_ENUM_NS(SignDomain)
+  Q_ENUM_NS(MarginSide)
+  Q_FLAG_NS(MarginSides)
+  Q_ENUM_NS(AntialiasedElement)
+  Q_FLAG_NS(AntialiasedElements)
+  Q_ENUM_NS(PlottingHint)
+  Q_FLAG_NS(PlottingHints)
+  Q_ENUM_NS(Interaction)
+  Q_FLAG_NS(Interactions)
+  Q_ENUM_NS(SelectionRectMode)
+  Q_ENUM_NS(SelectionType)
 /*! \internal
   Returns whether the specified \a value is considered an invalid data value for plottables (i.e.
@@ -386,15 +382,7 @@
+//no need to use Q_DECLARE_METATYPE on enum since Q_ENUM_NS adds enum as metatype automatically
 /* end of 'src/global.h' */
Only in qcustomplot: unpatched

Dear Miccs,

Can you explain how and where to apply this patch? Thanks a lot!

Kind regards, Jan

here you can download patched - ready to use file:

if you are scared of the contents of downloaded files just check its content by comparing the contents of this file with the original unmodified using for example total commander (on windows) or double commander / krusader on linux.

you can apply that patch yourself - but i cannot give you exact command(probably you are on windows) - git client can do it (from what i know) or other port of patch tool from linux.

on linux its simple -
patch -p2 < ../qcustomplot.patch

thats it.
google for a windows solution - its a "diff patch"

Dear Miccs

Thank you for this patch, it works perfect now

Thank you very much for this patch, it works!

God bless you miccs, genius

I solved this issue with /usr/bin/g++ in compilers path.

The patch works!!. Thank you so much! @miccs

This patch works perfectly with GCC 9.3.0 and Qt 6.2.1. Thank you so much~

Thank you for the patch!

I dont know if intentional, but the provided h file ist not identical with the patch. It is missing the line

extern const QMetaObject staticMetaObject; // in moc-run we create a static meta object for QCP "fake" object. This line is the link to it via QCP::staticMetaObject in normal operation as namespace

I added it back and it still works.

you shouldnt - it is intentional.
look here:
"Q_NAMESPACE makes an external variable, staticMetaObject, available. staticMetaObject is of type QMetaObject and provides access to the enums declared with Q_ENUM_NS/Q_FLAG_NS."

in other words: it is already there.
everything that has to be there is already present and this patch provides exact same functionality as original version - that was working before 6.2.

ah sorry i misread.

too bad i must've made an error when posting this patch.
the correct version is the one from the ready to use file.
so everybody please use that file - im lazy to generate new patch and post it here - if anybody else has time please do on my behalf.

Hi. Sorry im having troubles compiling qcustomplot from the source and the mediafire link seems to be broken. Someone has the files?

You can download patch from here: https://www.sendspace.com/file/dug7xs

Hi there,
the patch is working. Thank you very much.

Nice, it works! Thank you.

Your patch don't work, just created another error:

C:/Qt/Tools/mingw900_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: debug/qcustomplot.o: in function `QCPLayerable::moveToLayer(QCPLayer*, bool)':
C:\Users\Projects\QT\Demo2/../QNotePadDemo2/qcustomplot.cpp:1587: undefined reference to `QCPLayerable::layerChanged(QCPLayer*)'

Works perfectly! Thanks genius!

run perfect

Thanks for all this good information. I am on a MAC 12.2.1, with XCode 13.2.1 (and I seem to have XCode-beta 13.3 as well), using Qt version 6.2.3. I installed the patch (thanks a lot for that), but got an compiler warning that only complained about the savePdf member function. Since for my app I do not care about pdf format, I simply commented out lines 15236 - 15298 in the qcustomplot.cpp file (the savePdf implementation) and the declaration in the qcustomplot.h file at line 3882. It works like clockwork now.

wow, it works, thank you, miccs

Thank you for the patch!

same problem here using Q6.2.4 Windows 10 MingW1120_64

March 29, 2022, 13:14
by Maarten

need to remove content of savePDF implementation and not all demos run correctly some crash, did not look deeper into this.

Thanks a lot for the Patch


I landed on this page while searching how to solve the following errors:

'TypeCompletePair': must be a class or namespace when followed by '::'
'TypeCompletePair': left of '::' must be a class/struct/union
syntax error: identifier 'type' (compiling source file x64\Debug\moc\moc_qcustomplot.cpp)

I am using Qt 6.3.0, on Visual Studio 2022, Windows.

I am unable to understand from the above discussion how to use the provided file to solve the errors. Sorry, I am a beginner. Could anybody guide me with the steps required for the same?

Thanks a lot.

Thank you for the patch.

Thanks miccs, works perfectly!

Thanks for all efforts.

I tried the patch but in my case it lead to errors like:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\rpcndr.h:962: error: C2872: 'byte': ambiguous symbol
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared\rpcndr.h(962): error C2872: 'byte': ambiguous symbol
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared\rpcndr.h(191): note: could be 'unsigned char byte'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\cstddef(28): note: or 'std::byte'

Any advise? Many thanks.

FYI, QCP 2.1.1 establishes compatibility up to Qt6.4;
Thanks for the discussions here! The hints here helped me fix some compatibility issues. Modifications were necessary though to keep backward compatible with Qt4.6; As it turns out, MOC of Qt4.6 only has a very limited understanding of #if macro conditions, which gave me a bit of a headache. (For example, it can't expand QT_VERSION_CHECK, can you believe it? :D)

Great thx for patch. Also removed content of savePDF implementation

same problem here using Q6.2.4 Windows 10 MingW1120_64

March 29, 2022, 13:14
by Maarten