Reputation: 147
I was using widgets in my application, but I am migrating to qml because of the appearance but I intend to continue using C ++ in the banckground
class Usuario : public QObject{
Q_OBJECT
Q_PROPERTY(bool login WRITE login)
public:
Usuario(QObject *parent = nullptr);
~Usuario();
static bool login(const QString& usuario, const QString& senha);
};
When compiling I get an error indicating that the function does not receive any arguments, so how can I call the login function in qml?
Upvotes: 2
Views: 167
Reputation: 243897
You are confusing concepts, Q_PROPERTY does not serve to expose functions or methods but to create a property (more information here), what you should use is Q_INVOKABLE or Q_SLOT:
class Usuario : public QObject{
Q_OBJECT
public:
Usuario(QObject *parent = nullptr);
~Usuario();
Q_INVOKABLE static bool login(const QString& usuario, const QString& senha);
// or
// Q_SLOT static bool login(const QString& usuario, const QString& senha);
};
Upvotes: 3