本文整理汇总了C++中QQmlContext::nameForObject方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlContext::nameForObject方法的具体用法?C++ QQmlContext::nameForObject怎么用?C++ QQmlContext::nameForObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlContext
的用法示例。
在下文中一共展示了QQmlContext::nameForObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getId
QString Helper::getId(QQmlApplicationEngine *engine, QObject *obj)
{
QQmlContext *context = engine->contextForObject(obj);
if (!context) {
return "";
}
return context->nameForObject(obj);
}
示例2: traverseObject
/*!
Traverse QObject based items.
*/
void SceneGraphTraverse::traverseObject(TasObject* objectInfo, QObject* object, TasCommand* command)
{
Q_UNUSED(command);
QQuickItem* item = qobject_cast<QQuickItem*>(object);
if (item) {
QQmlContext* context = QQmlEngine::contextForObject(object);
if (context) {
QString name = context->nameForObject(object);
objectInfo->addAttribute("QML_ID", name);
}
#ifdef USE_QTQML_PRIVATE_HEADERS
addTypeInfo(item, objectInfo);
#endif
mTraverseUtils->addObjectDetails(objectInfo, object);
objectInfo->addAttribute("objectType", TYPE_QSCENEGRAPH);
QPointF point = item->mapToScene(QPoint());
// needed for visualizer
objectInfo->addAttribute("x", (int)point.x());
objectInfo->addAttribute("y", (int)point.y());
objectInfo->addAttribute("x_absolute", (int)point.x());
objectInfo->addAttribute("y_absolute", (int)point.y());
objectInfo->addAttribute("x_relative", item->x());
objectInfo->addAttribute("y_relative", item->y());
// TODO already included?
objectInfo->addAttribute("width", item->width());
objectInfo->addAttribute("height", item->height());
}
}