I'm trying with QT 5 + QML to create an application where after opening the file using fileDialog
it returns a message by a QT signal.
The application opens using a QML and initiates a call to a SLOT
in the class responsible. This class reads and then does some more work and returns a% w / o of the finished work to be submitted.
The code for main follows below:
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include "imagefilter.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ImageFilter filtro;
qmlRegisterType<ImageFilter>("ImageFilter", 1, 0, "ImageFilter");
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("filtro", &filtro);
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}
The class responsible for working with images:
#include <QObject>
#include <QString>
#include <QDebug>
class ImageFilter : public QObject
{
Q_OBJECT
public:
explicit ImageFilter(QObject *parent = 0);
signals:
void teste(const QString &path);
public slots:
void receiveImage(const QString path);
};
The
SIGNAL
is just a test that I am performing to validate if I can receive the information later it would return asignal teste
.
The QImage
that calls SLOT
to simplify the test.
void ImageFilter::receiveImage(QString path)
{
qDebug() << path;
emit teste("Teste");
}
Finally QML, I will post only the part responsible for receiving SIGNAL
because the part of SIGNAL
I do not have any problem.
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2
import ImageFilter 1.0
ImageFilter {
onTeste: image2.text: path
}
What would be expected to work because I used the qt-project.org documentation, but the onTest is not called at least the in-place text is not changed. In this case I used SLOT
because I did not find a way to work the same as that used to make SLOTS calls in C ++ with qmlRegisterType
.
If anyone can help in how to receive these signals. Thanks!