woboq/qmetaobject-rs

Qt 5.6: prelude import of register_enum

Closed this issue · 4 comments

Commit 4772476 by @sztomi rightfully imports qml_register_enum in the prelude, but qml_register_enum only gets generated on Qt 5.8+, due to its config directive:

/// Register the given enum as a QML type.
///
/// Refer to the Qt documentation for [qmlRegisterUncreatableMetaObject][qt].
///
/// [qt]: https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject
#[cfg(qt_5_8)]
pub fn qml_register_enum<T: QEnum>(
    uri: &CStr,
    version_major: u32,
    version_minor: u32,
    qml_name: &CStr,
) {
    let uri_ptr = uri.as_ptr();
    let qml_name_ptr = qml_name.as_ptr();
    let meta_object = T::static_meta_object();

    cpp!(unsafe [
            qml_name_ptr as "char *",
            uri_ptr as "char *",
            version_major as "int",
            version_minor as "int",
            meta_object as "const QMetaObject *"
        ] {
    #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
            qmlRegisterUncreatableMetaObject(
                *meta_object,
                uri_ptr,
                version_major,
                version_minor,
                qml_name_ptr,
                "Access to enums & flags only"
            );
    #endif
        })
}

Now, there are two version guards on this function. We can choose to drop the cfg()-guard, which exposes a no-op qml_register_enum via prelude, or we can choose to drop the inner guard, and add a guard on the prelude re-export.

I'm not sure which route to take here, but I'll gladly make a PR to fix this.

Sailfish OS devs are at it again 😄

Now, there are two version guards on this function. We can choose to drop the cfg()-guard, which exposes a no-op qml_register_enum via prelude, or we can choose to drop the inner guard, and add a guard on the prelude re-export.

We should use ALL guards required to make it work, no matter how many. Each level of indirection / re-export / usage should include a guard. In future, we should be more careful with guards too.

So I take it the right solution is to add the same guard to the re-export?

So I take it the right solution is to add the same guard to the re-export?

Yus.

Sailfish OS devs are at it again smile

Yes. Sorry :D

Maybe I should invest some time in a qt5.6 build on the CI...

Anyway, I'll supply the patch in 10, HMB.