QML注册类
QML和C++类进行信息交互,要通过函数注册的方式:
1、通过qmlRegisterType进行类的注册和引入
![请添加图片描述](https://i-blog.csdnimg.cn/blog_migrate/a2ff460cc31031bbf5a96c7bf2a1c987.png)
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include"QDebug"
#include <QObject>
#include <QQmlEngine>
#include <QQmlContext>
#include"test.h"
int main(int argc, char *argv[])
{
qmlRegisterType<Test>("Test", 1,2,"Test");
QGuiApplication app(argc, argv);
qmlRegisterType<FlowControl>("FlowControl", 1,2,"FlowCon");
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
QML关联C++信号
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6db0b5aab6c3a46e7b123d5288c88f22.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9e3ea2fde2836a5d0028ca3970360c73.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/21008525878975f346e782b2eb1a36eb.png)