c++ - 将 qml 注册的枚举作为参数发送到 c++ 方法
问题描述
我有这样的enum
课
class ScreenOrientation : public QObject
{
Q_OBJECT
public:
enum Orientation {
Unspecified = -1,
Landscape = 0,
Portrait = 1
};
Q_ENUM(Orientation)
};
注册于
qmlRegisterUncreatableType<ScreenOrientation>("Foo", 1, 0, "ScreenOrientation", QStringLiteral("Not creatable as it is an enum type"));
还有我的 QML 代码:
backend.setOrientation(ScreenOrientation.Landscape)
当我的 C++ 方法有int
作为参数时它正在工作
...
void setOrientation(int orientation);
...
但是,如果我使用ScreenOrientation::Orientation
作为方法参数,我会得到“错误:未知方法参数类型:ScreenOrientation::Orientation ”。我可以以某种方式ScreenOrientation::Orientation
用作方法参数吗?它看起来比只是漂亮得多int
。
解决方案
推荐阅读
- django - python social auth:从 Google OAuth2 获取电子邮件
- react-native - FireStore 多个 where 查询
- javascript - 尝试实现反应原生地图时出错
- amazon-web-services - AWS 更新 Cloudfront 域名
- amazon-web-services - -fopenmp 在 amazon linux 上不包括 omp.h?
- graphql - 动态生成 GraphQL 架构
- push-notification - 如何从浏览器获取推送通知权限的状态?
- asp.net - 返回 JSON 的 SQL Server
- go - 使用golang AddDate 计算日期的正确方法是什么
- machine-learning - 我需要帮助弄清楚哪种类型的程序员可以做我想做的事情