Make QAxBase/QAxWidget QDataStream operators hidden friends

Prompted by 4664acf185 adding QAxWidget
operators as non-member non-friends, make both QAxBase and QAxWidget
operator hidden friends, as we want all our operators to be these days.

This change is BC, but it's not 100% SC, because streaming of objects
that merely implicitly convert to QAxWidget/QAxBase, but are not
derived from them, now fails.

Also move the QAxWidget operators out-of-line, so we have some chance
of adding something to them, though the pre-existing QAxBase operators
mean adding anything there will change the serialization format
vis-a-vis 6.8 (nothing a QDataStream version upgrade can't solve,
though).

[ChangeLog][Potentially Source-Incompatiable Changes][QAxBase] The
QDataStream operators are now hidden friends, so they will only match
types which are QAxBase, or derived from it, not those that merely
implicitly convert to them. A backwards-compatible fix is to make the
conversion explicit and only call these operators on actual QAxBase
subclass objects.

Amends the start of the public history and
4664acf185.

Pick-to: 6.9
Change-Id: I60fe1ba10f7478c2dfedf33cc45bbc257f297a4b
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2025-01-27 14:15:53 +01:00
parent ee0189bede
commit 6f495e77a5
3 changed files with 50 additions and 36 deletions

View File

@ -116,6 +116,31 @@ private:
int internalInvoke(QMetaObject::Call, int index, void **v);
bool dynamicCallHelper(const char *name, void *out, QList<QVariant> &var,
QByteArray &type, unsigned flags = 0);
private:
#ifndef QT_NO_DATASTREAM
friend QDataStream &operator>>(QDataStream &s, QAxBase &c)
{
QAxBase::PropertyBag bag;
const QSignalBlocker blocker(c.qObject());
QString control;
s >> control;
c.setControl(control);
s >> bag;
c.setPropertyBag(bag);
return s;
}
friend QDataStream &operator<<(QDataStream &s, const QAxBase &c)
{
QAxBase::PropertyBag bag = c.propertyBag();
s << c.control();
s << bag;
return s;
}
#endif // QT_NO_DATASTREAM
};
template <> inline QAxBase *qobject_cast<QAxBase*>(const QObject *o)
@ -137,30 +162,6 @@ inline QString QAxBase::generateDocumentation()
return qax_generateDocumentation(this);
}
#ifndef QT_NO_DATASTREAM
inline QDataStream &operator >>(QDataStream &s, QAxBase &c)
{
QAxBase::PropertyBag bag;
const QSignalBlocker blocker(c.qObject());
QString control;
s >> control;
c.setControl(control);
s >> bag;
c.setPropertyBag(bag);
return s;
}
inline QDataStream &operator <<(QDataStream &s, const QAxBase &c)
{
QAxBase::PropertyBag bag = c.propertyBag();
s << c.control();
s << bag;
return s;
}
#endif // QT_NO_DATASTREAM
QT_END_NAMESPACE
#ifndef Q_COM_METATYPE_DECLARED

View File

@ -2410,4 +2410,24 @@ bool QAxWidget::translateKeyEvent(int message, int keycode) const
return translate;
}
#ifndef QT_NO_DATASTREAM
/*!
\internal
*/
// friend
QDataStream &operator>>(QDataStream &s, QAxWidget &w)
{
return s >> static_cast<QAxBase &>(w);
}
/*!
\internal
*/
// friend
QDataStream &operator<<(QDataStream &s, const QAxWidget &w)
{
return s << static_cast<const QAxBase &>(w);
}
#endif // QT_NO_DATASTREAM
QT_END_NAMESPACE

View File

@ -74,6 +74,11 @@ private:
Q_DECLARE_PRIVATE(QAxWidget)
friend class QAxClientSite;
#ifndef QT_NO_DATASTREAM
friend QDataStream &operator>>(QDataStream &s, QAxWidget &w);
friend QDataStream &operator<<(QDataStream &s, const QAxWidget &w);
#endif
};
template <> inline QAxWidget *qobject_cast<QAxWidget*>(const QObject *o)
@ -88,18 +93,6 @@ template <> inline QAxWidget *qobject_cast<QAxWidget*>(QObject *o)
return static_cast<QAxWidget *>(result);
}
#ifndef QT_NO_DATASTREAM
inline QDataStream &operator>>(QDataStream &s, QAxWidget &w)
{
return s >> static_cast<QAxBase &>(w);
}
inline QDataStream &operator<<(QDataStream &s, const QAxWidget &w)
{
return s << static_cast<const QAxBase &>(w);
}
#endif
QT_END_NAMESPACE
#endif // QAXWIDGET_H