You don't really provide a lot of information. Based on what's there the answer has been given already. Generally you need these steps:
1. Create c++ class that contains the Q_OBJECT macro
class WorkspaceWidget
{
Q_OBJECT
public:
// your implementatin goes here...
// whatever function you want to call from qml must be made invokable with the proper macro declaration
Q_INVOKABLE void foo();
}
class WorkspaceWidget
{
Q_OBJECT
public:
// your implementatin goes here...
// whatever function you want to call from qml must be made invokable with the proper macro declaration
Q_INVOKABLE void foo();
}
To copy to clipboard, switch view to plain text mode
2. Register the class in main.cpp
qmlRegisterType<WorkspaceWidget>("WorkspaceWidgetNameSpace", 2, 0, "WorkspaceWidgetQml");
// WorkspaceWidget: Your class
// WorkspaceWidgetNameSpace: a namespace that has not yet been used. Can be anything, but must be unique
// WorkspaceWidgetQml: Some name that you give to handle it in a qml file. Can be anything, but must be unique
qmlRegisterType<WorkspaceWidget>("WorkspaceWidgetNameSpace", 2, 0, "WorkspaceWidgetQml");
// WorkspaceWidget: Your class
// WorkspaceWidgetNameSpace: a namespace that has not yet been used. Can be anything, but must be unique
// WorkspaceWidgetQml: Some name that you give to handle it in a qml file. Can be anything, but must be unique
To copy to clipboard, switch view to plain text mode
3. in some qml-file
// import your name space with major and minor version
import WorkspaceWidgetNameSpace 2.0
// declare your class, as qml is a declarative environment
WorkspaceWidgetQml {
id: workspaceWidgetID
}
// do with it what you want
TextButton {
text: "1x1"
onClicked: { workspaceWidgetID.setLayout(WorkspaceWidget.Layout_1x1); }
}
// import your name space with major and minor version
import WorkspaceWidgetNameSpace 2.0
// declare your class, as qml is a declarative environment
WorkspaceWidgetQml {
id: workspaceWidgetID
}
// do with it what you want
TextButton {
text: "1x1"
onClicked: { workspaceWidgetID.setLayout(WorkspaceWidget.Layout_1x1); }
}
To copy to clipboard, switch view to plain text mode
Bookmarks