Qt 6.5 How to dynamically create a QMetaMethodReturnArgument type?

106 Views Asked by At
        void* filePtr = nullptr;

        const auto couldInvoke = method.invoke(
            path.get(),
            Qt::DirectConnection,
            QReturnArgument(method.returnMetaType().name(), filePtr),
            Q_ARG(QString, fileName)
        );

I used to create an dynamic QReturnArgument as shown above. Invoking works, it is against the documentation, but I don't use the macros, and it is working.

in Qt 6.5 they introduced:

struct QMetaMethodReturnArgument
{
    const QtPrivate::QMetaTypeInterface *metaType;
    const char *name;
    void *data;
};

I have no clue how to create this QMetaTypeInterface dynamically for every type based on QMetaType:

class QMetaTypeInterface
{
public:
    ushort revision; // 0 in Qt 6.0. Can increase if new field are added
    ushort alignment;
    uint size;
    uint flags;
    QMTI_MUTABLE QBasicAtomicInt typeId;

I can not use that:

template <typename T> void qReturnArg(const T &&) = delete; 
template <typename T> inline QMetaMethodReturnArgument qReturnArg(T &data) 
{     
    return QtPrivate::Invoke::returnArgument(nullptr, data); 
}

namespace QtPrivate {
class QMetaTypeInterface;
template<typename T> constexpr const QMetaTypeInterface *qMetaTypeInterfaceForType();
}

Is there an easier solution?

declaring it manually works, but it's too much effort.

I'm expecting to get a QMetaMethodReturnArgument just by the QMetaType, name and data.

1

There are 1 best solutions below

0
On

It's possible to use the following:

QMetaMethodReturnArgument(method.returnMetaType().iface(), nullptr, std::addressof(entity));