-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error: no match for ‘operator<<’ #113
Comments
Hello, I don't understand what is exactly the issue. |
In this file:QxOrm/include/QxSerialize/QDataStream/QxSerializeQDataStream_QSharedPointer.h:50
there are two global operators:
template <typename T>
QDataStream & operator<< (QDataStream & stream, const QSharedPointer<T> & t)
{
qint8 iIsNull = (t ? 0 : 1);
stream << iIsNull;
if (t) { stream << (* t); } // it needs the type T to implement the operator <<()
return stream;
}
template <typename T>
QDataStream & operator>> (QDataStream & stream, QSharedPointer<T> & t)
{
qint8 iIsNull = 0;
stream >> iIsNull;
if (! iIsNull) { t = QSharedPointer<T>(new T()); stream >> (* t); }
else { t = QSharedPointer<T>(); }
return stream;
} The reason for my issue is that type T doesn't implement QDataStream & operator<< (QDataStream & stream, T). Since this header file is included by the QxOrm.h, the operator will be applied anywhere where it includes the QxOrm.h. |
If the compiler requires a specialization for the template QSharedPointer (or whatever type) : this is because somewhere in the code, this specialization is required : so operator>> or operator<< are used somewhere (maybe by QxOrm itself (?)). Maybe you have used the QCustomPlot class as a property of a persistent class registered in QxOrm context : in this case, you should go to the documentation here : https://www.qxorm.com/qxorm_en/manual.html#manual_460 |
I'm not using the QCustomPlot class as a property of a persistent class. The persistent class and the QCustomPlot are all members of a parent class, so I need include the persistent class and the QCustomPlot headers together. The persistent class is generated by the QEntityEditor. Yes, you are right, I can resolve this problem by simply implementing the operator<<() and the operator>>() for QCustomPlot, but I don't need to persistent the QCustomPlot. also, the QCustomPlot is a third-party library, so it is not a good idea to work around it. Since the QSharedPointer is used in the macro Q_OBJECT which is used in all Qt objects, it is used widely. So using the QxOrm in Qt non-persistent classes will cause a lot of compiling errors. I think the Q_OBJECT macro is a good idea as a way to make a persistent class. If a class needs work as a persistent class, we could put a macro in that class declaration. I recommend moving the operators into the declaration of the persistent class headers. |
Thx for the details, this is interesting. Maybe a solution could be to move :
From QxOrm.h file to QxOrm_Impl.h file. QxOrm_Impl.h is included in each *.cpp files for each persistent classes (so not in headers). I don't know if it will break something else, but you could try that. |
In the above error message, the following global operator << needs all classes, who uses the QSharedPointer, should implement the operator << for the class QDataStream :
QDataStream & operator<< (QDataStream & stream, const QSharedPointer<T> & t)
As soon as the QxOrm.h is included and there is the macro Q_DECLARE_METATYPE in one source file, it will cause this issue. So I think it is better to hide the global operator << from the QxOrm.h. Maybe it could be moved to a single header which could be included when needed.
To reproduce the above error, just include the QxOrm.h and the qcustomplot.h which is from the repository: https://github.com/vasilyaksenov/QCustomPlot
The text was updated successfully, but these errors were encountered: