QCustomPlot Discussion and Comments

Cannot compile in vs2010Return to overview

Hello!
I tried to compile simple app with only included qcustomplot.h and qcustomplot.cpp in my environment VS2010 and Qt 5.0.1 but get the following error:

qcustomplot.cpp
1>qcustomplot.cpp(915): error C2664: 'QWeakPointer<T>::QWeakPointer(const QWeakPointer<T> &)' : cannot convert parameter 1 from 'QCPLayerable *' to 'const QWeakPointer<T> &'
1> with
1> [
1> T=QCPLayerable
1> ]
1> Reason: cannot convert from 'QCPLayerable *' to 'const QWeakPointer<T>'
1> with
1> [
1> T=QCPLayerable
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>qcustomplot.cpp(1093): error C2679: binary '=' : no operator found which takes a right-hand operand of type 'QCPLayerable *' (or there is no acceptable conversion)
1> C:\Qt\Qt5.0.1\5.0.1\msvc2010\include\QtCore/qsharedpointer_impl.h(550): could be 'QWeakPointer<T> &QWeakPointer<T>::operator =(const QWeakPointer<T> &)'
1> with
1> [
1> T=QCPLayerable
1> ]
1> C:\Qt\Qt5.0.1\5.0.1\msvc2010\include\QtCore/qsharedpointer_impl.h(558): or 'QWeakPointer<T> &QWeakPointer<T>::operator =(const QSharedPointer<T> &)'
1> with
1> [
1> T=QCPLayerable
1> ]
1> while trying to match the argument list '(QWeakPointer<T>, QCPLayerable *)'
1> with
1> [
1> T=QCPLayerable
1> ]

With best regards, Serg

Adding - The old version QCustomPlot 0.9.0 is compiled normally

Hi Serg,

I'm afraid the Qt team has introduced some serious issues with what they've done to QWeakPointer. It caused very long (Qt-)forum and mailing list discussions. The thing is this: Without large announcement they removed the QWeakPointer QObject-tracking capability and undeprecated the use of QPointer. So from Qt4 to Qt5, they basically switched the meaning between QWeakPointer and QPointer, forcing libraries to choose between Qt4 and Qt5 compatibility. The only way out of this is using the macro

#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(0, 0, 0)

which re-activates the QWeakPointer QObject-tracking capability in Qt5. The only Problem with that is (as I remeber vaguely from the mailing list) that there was some bug in Qt 5.0.1 which required MSVC users to actually compile Qt 5.0.1 with that define. It is not enough to just have that define in the application or the library, as is the case with QCustomPlot. I think that problem was fixed with Qt 5.0.2 and it doesn't seem to happen with non-MSVC compilers at all.

Trust me, many library developers and myself are very frustrated about the poor decisions the Qt devs have made in this respect. At the moment, there isn't much I can do about it. So I'm afraid the options that come to mind aren't too great: Use Qt4.x.x, or use Qt 5.0.2 (which should work if I remember correctly), or use QCP 0.9 (which doesn't use QWeakPointer), or don't use MSVC. Pick the least painful :).

Thanks for quick and detail response.
I have tried to compile your new QCustomPlot with Qt versions 5.0.2 and 5.1.0 (it is new) and it doesn't compiled too. (Errors are the same.. ). Unfortunatly, i cannot refuse from VS2010 because the Qt application is only small part of our C++ development. Also I need your new version 1.0.0 because it has a possibility to create many Y-axes.
I don't see decision yet.. May be the changing QWeakPointer to QPointer inside your library?..

The problem with switching back to QPointer is that this would mean using the slow/broken and thus deprecated QPointer implementation in Qt4. If I knew that all users of QCP would only use Qt5 that would be fine, because QPointer was re-done from scratch in Qt5 and works good. However, the vast majority of my users use Qt4, so switching to QPointer wouldn't be beneficial to them. How bad it would be performance wise, I still need to evaluate. If it turns out that it's not significant, I will indeed try to find a solution with QPointer, to get rid of that deprecated flag.

By the way, I forgot one option you still have: compile Qt 5.x.x (preferably 5.1 or 5.0.2) with the deprecated flag mentioned above.

Couldn't you use some kind of define macro, something like :

#if QT5
#define QCustomPlotPointer QPointer
#else
#define QCustomPlotPointer QWeakPointer
#end

this would let you get rid of the deprecated macro (actually I am not completely sure of the side effect of the QT_DISABLE_DEPRECATED_BEFORE macro, I would tend to think it's better to avoid it...)

The errors you describe disappear for me with VS2010 if I turn off precompiled headers on the QCustomPlot source file, qcustomplot.cpp. You can control the precompilation preference for each source file.