//Login.h
#include <QObject>
#include <QDebug>
class Login : public QObject
{
Q_OBJECT
public:
explicit Login(QObject * parent = 0);
Q_INVOKABLE void loginMessage(QString userName, QString passWord);
};
//Login.cpp
#include "Login.h"
Login::Login(QObject *parent) : QObject(parent)
{
}
void Login::loginMessage(QString userName, QString passWord)
{
qDebug() << "loginMessage" << userName << passWord;
}
//main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "Login.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
Login login;
engine.rootContext()->setContextProperty("LOGIN",&login);
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
return app.exec();
}