[SOLVED] Defining own QML type - can i define method ?
-
Hi, i was wondering about how i can define own C++ methods for QML component.
@
class TimeModel : public QObject
{
Q_OBJECT
Q_PROPERTY(int hour READ hour NOTIFY timeChanged)
Q_PROPERTY(int minute READ minute NOTIFY timeChanged)
...
@This is code example from documentation. Thereis defined properties, but i want to define method to which i will call later in QML code, like this:
@TimeModel {
id: tm
}..
tm.someMethod()
..@I didnt found Q_METHOD() in qt. Anny suggestions ??
-
There are 2 ways:
- mark methods with Q_INVOKABLE
- make them be public slots
-
Ok, thanks. So both conditions are needed ?
- mark methods with Q_INVOKABLE
- make them be public slots
Both of them ?
-
No. Either one will work.
-
Ok, thanks. That worked.