我正在尝试将我的 C++ 类实现到 QML 中,通过设置上下文属性来识别该类,我可以成功调用该类并查看所有函数,但在运行时无法识别它们并返回错误:TypeError: Property 'getSrcImage' object Wrapper(0x7b211cbf10) 不是一个函数,我相信这些函数没有被正确地声明到 QML 但不知道如何修复..
.h 文件
class Wrapper : public QObject
{
Q_OBJECT
Q_INVOKABLE void initiateLipLib();
Q_INVOKABLE bool setMat();
Q_INVOKABLE QImage displayfeed();
Q_INVOKABLE void getMatFeed();
Q_INVOKABLE int liptrainstart(cv::Mat Image);
Q_INVOKABLE void liptrainingend();
Q_INVOKABLE float getDistance();
Q_INVOKABLE std::string getstatus();
Q_INVOKABLE void clear();
public:
explicit Wrapper(QObject *parent = 0);
QString getSrcImage();
Run Code Online (Sandbox Code Playgroud)
主程序
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
#include <QtQml/QQmlContext>
#include <QDebug>
#include "wrapper.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine …Run Code Online (Sandbox Code Playgroud)