0
I am trying with QT 5 + QML to create an application where after opening the file using the fileDialog
it returns a message by a QT signal.
The application opens using a QML and initiating a call to a SLOT
in the responsible class. This class performs the reading and later will do some more work and return for a SIGNAL
the work completed to be presented.
The main code 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 the work of the 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 teste
is just a test I’m running to validate if I can receive the information later would return aQImage
.
The SLOT
who makes the call from SIGNAL
to simplify the test.
void ImageFilter::receiveImage(QString path)
{
qDebug() << path;
emit teste("Teste");
}
Finally the QML, I will post only the party responsible for receiving the SIGNAL
for the part of SLOT
I have no problem at all.
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 documentation of Qt-project.org, but onTeste is not called at least the text in the place is not changed. In this case I used the qmlRegisterType
because I couldn’t figure out a way to work the same way used to make SLOTS calls in C++ with engine.rootContext()->setContextProperty("filtro", &filtro);
.
If anyone can help in receiving these signals. Grateful!
Yes, but as far as the documentation stated using {...}only for more than one line even, as what I want is only the alteration of a text there is no need to use it {...}.
– Thiago Prado