[Interest] [Qt 3D] What is AspectCreateFunction? (or how to expose a custom aspect to QML)

Adrián Chaves Fernández adriyetichaves at gmail.com
Sat Apr 30 12:08:54 CEST 2016


The Qt input system does not work for me. The Qt key event system, with its
special handling of modifier keys, is designed for (desktop) applications,
not for games. For example, as far as I can see, there is no reliable way
for me to use modifier keys, such as Shift or Ctrl, as regular keys. So I
plan to create a custom input aspect that uses SDL for input.

I’ve had a look at the QInputAspect code, and now I am trying to create the
most basic aspect, so that I can verify that the aspect barebones are in
place before I start implementing my custom input handling into this new
aspect. So right now I have a QAbstractAspect subclass that implements a
constructor and overrides jobsToExecute(), onInitialize() and onCleanup().

Now I am trying to figure out how to define the ‘name’ of my custom input
aspect, the keyword that I must pass to the ‘aspects’ property of the
‘Scene3D’ QML element so that it instantiates my custom aspect.

At the end of ‘qinputaspect.cpp’ I found QT3D_REGISTER_NAMESPACED_ASPECT(),
which receives the "input" string as a parameter. I assume that this is the
code that determines that passing "input" to the ‘aspects’ property of the
‘Scene3D’ QML element adds an instance of the QInputAspect aspect to the
simulation. So I am trying to do that in my code as well.

Since my custom aspect (InputAspect) does not have a namespace, I cannot
just use the QT3D_REGISTER_NAMESPACED_ASPECT() macro, so instead I tried to
replicate its code. This is the result:

    void qt3d_QAspectFactory_addDefaultFactory(const QString &, const
QMetaObject *, AspectCreateFunction);

    *(*AspectCreateFunction)(QObject *)
*qt3d_InputAspect_createFunction(QObject *parent)
    {
        return new InputAspect(parent);
    }

    void qt3d_InputAspect_registerFunction()
    {

qt3d_QAspectFactory_addDefaultFactory(QStringLiteral("chopshop_input"),
&InputAspect::staticMetaObject, qt3d_InputAspect_createFunction);
    }

    Q_CONSTRUCTOR_FUNCTION(qt3d_InputAspect_registerFunction)

But this code fails to compile:

    …/inputaspect.cpp:46:82: error: ‘AspectCreateFunction’ has not been
declared
    void qt3d_QAspectFactory_addDefaultFactory(const QString &, const
QMetaObject *, AspectCreateFunction);

^
I’ve grepped the sources of Qt 3D 5.6 for such a name, but the only
appearances seem to be those 2 in the QT3D_REGISTER_NAMESPACED_ASPECT()
macro definition:

    [gallaecio at afonso qt3d]$ grep AspectCreateFunction * -FIR
    src/core/aspects/qabstractaspect.h:        typedef QAbstractAspect
*(*AspectCreateFunction)(QObject *); \
    src/core/aspects/qabstractaspect.h:        QT3DCORESHARED_EXPORT void
qt3d_QAspectFactory_addDefaultFactory(const QString &, const QMetaObject *,
AspectCreateFunction); \

I don’t know what to do now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160430/cb120ed3/attachment.html>


More information about the Interest mailing list