QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

Aravor

I just want to connect a cpp signal to a qml slot and tried different ways, but it always results in the same QML-Error at runtime: Cannot assign to non-existent property "onProcessed"! Why?

This is my Cpp Object:

#include <QObject>

class ImageProcessor : public QObject
{
    Q_OBJECT
public:
    explicit ImageProcessor(QObject *parent = 0);

signals:
    void Processed(const QString str);
public slots:
    void processImage(const QString& image);
};

ImageProcessor::ImageProcessor(QObject *parent) :
    QObject(parent)
{
}

void ImageProcessor::processImage(const QString &path)
{
    Processed("test");
}

This is my main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml>

#include "imageprocessor.h"

int main(int argc, char *argv[])
{
    qmlRegisterType<ImageProcessor>("ImageProcessor", 1, 0, "ImageProcessor");

    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:///main.qml")));

    return app.exec();
}

And this is my QML file

import QtQuick 2.2
import QtQuick.Window 2.1
import QtMultimedia 5.0

import ImageProcessor 1.0

Window {
    visible: true
    width: maximumWidth
    height: maximumHeight

    Text {
        id: output
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }

    VideoOutput {
        anchors.fill: parent
        source: camera
    }

    Camera {
        id: camera
        // You can adjust various settings in here

        imageCapture {
            onImageCaptured: {
                imageProcessor.processImage(preview);
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            camera.imageCapture.capture();
        }
    }

    ImageProcessor{
        id: imageProcessor
        onProcessed: {
            output.text = str;
        }
    }
}

I am using QT 5.3.0 with Qt Creator 3.1.1, which is even suggesting me onProcessed and highlights it correctly.

epsilon

For exposing signals from C++ Object you must follow some naming conventions:

  • Signal must begin by a lowercase letter in your C++ code, i.e void yourLongSignal()
  • Signal handler in QML will be named on<YourLongSignal>

So, the only thing you have to edit in your code is to change

signals:
    void processed(const QString& str);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

QML: Using cpp signal in QML always results in "Cannot assign to non-existent property"

From Dev

QML interaction with CPP : property double results in NaN

From Dev

C++ using signal slots for QML

From Dev

QML On Item Changed Signal

From Dev

Exposing an enum in a QML signal

From Dev

Signal between QML with Repeater

From Dev

QML - connect a signal from c++ to qml

From Dev

Qt-how to connect a function to a signal in qml with python? using QQmlApplicationEngine

From Dev

Qt QML draw in cpp subclass

From Dev

emit qml signal on start application

From Dev

QML signal QT slot with QQuickView

From Dev

emit qml signal on start application

From Dev

Nested QML element onCompleted's signal not blocking the instanciation of QML objects

From Dev

Using a Loader for a string of QML

From Dev

QML: Using a Canvas in a RadioButtonStyle

From Dev

Using dialogs in QML

From Dev

How to use a custom Qt type with a QML signal?

From Dev

QML: one signal, multiple slots, possible?

From Dev

How to set property type of qml signal?

From Dev

PyQt5 QML Signal to Python Slot?

From Dev

QAbstractListModel dataChanged signal not updating ListView (QML)

From Dev

QML: Overriding a signal handler from other element

From Dev

How to set property type of qml signal?

From Dev

Fail To Connect Qml signal to C++ Slot

From Dev

Use createComponent in qml but the status is always error

From Dev

Mimedata of dynamic qml object is always empty

From Dev

Draw rectangle using mouse QML

From Dev

QML not using Thin font weight

From Dev

Using a Node JS library with QML