QML and C++ interaction. Need advice
-
Hello guys
Again I need your help. I'm implementing some kind of multi-tab application where each tab holds an editor that in turn shows somehow a file content. The application components/layouts/etc are specified using QML, but the editor itself is written in C++. To be able to use C++ editor from QML, I'm using standard approach:
@qmlRegisterType<MyEditor>("Specialeditor", 1, 0, "MyEditor");@So in my QML file I can do something like that:
@import Specialeditor 1.0
Rectangle {
id:main
...
MyEditor {
...
}
}@But now I would like to ask my editor to open a certain file (and it's not just a file name or string based content, in my case it would by specialy styled document that I have to prepare, I mean it's not a standard type that QML would understand). How I can ask certain editor (since I can have a lot of them) to show certain styled document (namely C++ object)?
This way is not going to help as I understand:
@viewer.rootContext()->setContextProperty(QStringLiteral("styledDocument"), getMyStyledDocument());@
Since I cannot specify certain editor instance that has to open the document. Any thoughts?Thanks a lot,
Maxim -
Hi,
I'm not sure I understood your question but if you give an id to your editors or if you know the indices of your tabs, you can call slots of your editor instances to perform specific actions in given editor. A slot is called like a javascript function: @myReference.calledFunction(args);@