ActiveQt: resolve enum parameter types by unqualified name
Since dumpcpp started qualifying type names with the type library's
namespace (commit 415da4185ffeaf6d1d773e7f390e417a75246ae9, "dumpcpp:
Qualify type names"), a method or property parameter of a COM enum type
is recorded in the meta object fully qualified, e.g. "MyTypeLib::MyEnum",
while the enumerator itself is registered under its unqualified declared
name "MyEnum".
A COM enum has no C++ metatype, so QAxBase converts an enum argument to
int only when QMetaObject::indexOfEnumerator() finds a matching
enumerator. The exact-string lookup failed for the qualified name, so the
argument was never packed into a VARIANT and IDispatch::Invoke rejected
the call with a non-standard HRESULT, reported as "Error calling IDispatch
member <name>: Unknown error". The byref output parameter was left
unpopulated.
Look the enumerator up by its exact name first and, if that misses, retry
with the unqualified tail (after the last "::"), at both enum-lookup
sites, in internalInvoke() and dynamicCallHelper().
That lookup, however, is not always reached: when dumpcpp hoists the enum
to genuine namespace scope (as it does whenever the enum is declared in
the type library itself), the qualified name also resolves to a real,
distinct QMetaType via QMetaType::fromName(), and internalInvoke() used
that unconditionally before ever consulting the meta object's enumerators.
The resulting QVariant, wrapping the enum's own custom metatype instead of
a plain int, then reached QVariantToVARIANT()'s generic fallback for
custom types (id() >= QMetaType::User), which assumes any such type is a
QAxObject-wrapping COM container and blindly reinterprets its raw storage
as a QAxObject**, calling queryInterface() through it and crashing.
Give the enumerator lookup precedence over QMetaType::fromName() in
internalInvoke(), and make the QVariantToVARIANT() fallback recognize
QMetaType::IsEnumeration and pack the value as a plain int instead of
assuming a container, so a resolvable qualified enum type name can no
longer bypass or break the enum handling.
Add a regression test in tests/auto/qaxobjectcom that adds an enum to the
in-process COM test server and round-trips a value through a dumpcpp-
generated method, reproducing both failure modes.
Fixes: QTBUG-148520
Pick-to: 6.11 6.12
Change-Id: I0a4473765120b6e76a95c98213bee3c41fd39b99
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>