QCustomPlot Discussion and Comments

MS VS2015 a lot of Warnings C4244Return to overview

Hello,

there are a lot of conversion compiler warnings at QCustomPlot:
Windows 7-64
VisualStudio 2015
QT 5.8
QCustomPlot: 2.0
all 32 bit

For example:
Warning C4244 'argument': conversion from 'const double' to 'int', possible loss of data (compiling source file ..\...\....cpp) ... ...\qcustomplot\qcustomplot.h 403
Warning C4244 '=': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 837
Warning C4244 '=': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 838
Warning C4244 '=': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 858
Warning C4244 '=': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 859
Warning C4244 '=': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 880
Warning C4244 '=': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 881
Warning C4244 '=': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 912
Warning C4244 '=': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 913
Warning C4244 'argument': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qmatrix4x4.h 1091
Warning C4244 'argument': conversion from 'double' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qquaternion.h 205
Warning C4244 'initializing': conversion from 'double' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qquaternion.h 254
Warning C4244 'initializing': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qvector3d.h 155
Warning C4244 'initializing': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qvector3d.h 157
Warning C4244 'initializing': conversion from 'int' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qvector4d.h 147
Warning C4244 'initializing': conversion from 'qreal' to 'float', possible loss of data (compiling source file ..\...\....cpp) ... ...\qt\5.8.0-32\5.8\msvc2015\include\qtgui\qvector4d.h 149


By the way, unfortunatelly is this sort of warning default disabled at QT:
In qglobal.h comment out this line:
# pragma warning(disable: 4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */

Best regards and thanks for your widget
user

Hi! Thanks for the feedback!

As far as I can see those are false positives for QCustomPlot. Screen pixels never exceed 2^16 = 65536, which is well within the mantissa bounds of float. Even for off-screen coordinate transforms, it can go up to about 16.8e6 before float becomes imprecise, and at that scale, it doesn't matter whether the LSB of int is lost or not. The important thing is it doesn't wrap, and that's true for float. I generally dislike the qreal/float usage of Qt libraries, but that's not my decision and I have to interface with it. Their decision does make sense in light of supporting embedded platforms which can't handle fast double fp arithmetic and are limited in terms of memory.

Also, most of the warnings you posted come from Qt sources themselves which I can't change. So overall it looks like it's best to not comment out that #pragma, because it was put there by the Qt devs since the warning is too fragile and creates 99% false positives rather than useful hints for bugs.