根据用户位置识别在 Qt Creator 中打开的 QML 文件中的上下文
目前我正在为 Qt Creator 开发插件,它应该为我提供语义信息 基于在文本编辑器中打开的 QML 文件中的用户位置(设置光标的位置)。 例如,如果我们有以下 QML 文件:
Rectangle {
width: 200
height: 200
color: "blue"
Image {
source: "pics/logo.png"
anchors.centerIn: parent
}
}
并且用户单击“颜色”插件应该告诉它它位于 Rectangle 对象内部。
我尝试使用以下代码:
const QmlJS::Snapshot snapshot = modelManager->snapshot();
const QmlJS::Document::Ptr doc = snapshot.document(fileName);
QmlJS::AST::Node *node = doc->ast();
const QmlJS::Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
qDebug() << "QML class" << scopeObject->className();
但返回的scopeObject为空。文档的ast()和bind()也为空,尽管文档->源显示了正确的源文件并且它被解析。 问题是如何获取scopeObject或者是否有其他方法可以做到这一点。
干杯
Currently I'm developing plugin for Qt Creator which which should give me semantic information
based on user location in QML file opened in text editor (where cursor is set).
For example, if we have the following QML file:
Rectangle {
width: 200
height: 200
color: "blue"
Image {
source: "pics/logo.png"
anchors.centerIn: parent
}
}
and user clicks on 'color' plugin should tell that it is inside Rectangle object.
I tried to use the following code:
const QmlJS::Snapshot snapshot = modelManager->snapshot();
const QmlJS::Document::Ptr doc = snapshot.document(fileName);
QmlJS::AST::Node *node = doc->ast();
const QmlJS::Interpreter::ObjectValue *scopeObject = doc->bind()->findQmlObject(node);
qDebug() << "QML class" << scopeObject->className();
but scopeObject returned is null. ast() and bind() of document are also null, though the document->source shows the correct source file and it is parsed.
The question is how to get the scopeObject or are there any other ways to do this.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论