[Solved] Qt on Android : custom module not installed
-
Hello,
I am very new to QML and I am developping an app using Qt 5.2.1 on CentOS 6.4
When deploying my app on my android device I get the message : "could not load : assets :/qml/MyProject/MyPage.qml:5 module "ImageProcessor" is not installed[EDIT] this problem comes also when I compile in Desktop mode. My post may not be at the right part of the forum. [/EDIT]
I already checked previous posts on this forum and I checked that :
- my call to qmlRegisterType is before the definiton to the main qml file
- my C++ object inherits from QObject
I used http://kunalmaemo.blogspot.fr/2013/06/using-qml-camera-and-passing-image-to-c.html as my starting point.
Here is the code :
main.cpp
@
int main(int argc, char *argv[])
{
qmlRegisterType<ImageProcessor>("ImageProcessor",1,0,"ImageProcessor");QGuiApplication app(argc, argv); QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral("qml/MyProject/main.qml")); viewer.showExpanded(); return app.exec();
}@
ImageProcessor.cpp
@#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickImageProvider>
#include <QDebug>#include "ImageProcessor.h"
ImageProcessor::ImageProcessor(QObject parent) :
QObject(parent)
{
}
void ImageProcessor::processImage(const QString & filename)
{
QUrl imageUrl(filename);
QQmlEngine * engine = QQmlEngine::contextForObject(this)->engine();
QQmlImageProviderBase * imageProviderBase = engine->imageProvider(imageUrl.host());
QQuickImageProvider imageProvider = static_cast<QQuickImageProvider*>(imageProviderBase);
QSize imageSize;
QString imageId = imageUrl.path().remove(0,1);
QImage image = imageProvider->requestImage(imageId,&imageSize,imageSize);
if(!image.isNull()){}
}@
ImageProcessor.h
@#include <QObject>class ImageProcessor : public QObject
{
Q_OBJECTpublic:
explicit ImageProcessor(QObject *parent = 0);signals:
public slots:
Q_INVOKABLE void processImage(const QString & filename);};@
MyPage.qml
@
import QtQuick 2.0
import QtMultimedia 5.0
import ImageProcessor 1.0Rectangle {
anchors.fill: parent//shows live preview from camera VideoOutput { source: camera anchors.fill: parent focus : visible } //shows captured image Image { id: photoPreview anchors.fill: parent fillMode: Image.PreserveAspectFit } Camera { id: camera imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash captureMode: Camera.CaptureStillImage exposure { exposureCompensation: -1.0 exposureMode: Camera.ExposurePortrait } flash.mode: Camera.FlashRedEyeReduction imageCapture { onImageCaptured: { photoPreview.source = preview imageProcessor.processImage(preview); } } } MouseArea{ anchors.fill: parent onClicked: { camera.imageCapture.capture(); } } //image processor for further image processing
ImageProcessor{
id: imageProcessor
}
}@My .pro file:
@# Add more folders to ship with the application, here
folder_01.source = qml/MyProject
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
ImageProcessor.cppInstallation path
target.path =
Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()#allow to use the camera
QT += multimedia
QT += declarativeHEADERS +=
ImageProcessor.h
@Could this be related to thje QML_IMPORT_PATH ? Any other idea about this ?
Thanks for your help.
François -
Ok I finally found it :)
The ImageProcessor class should inherits from QQuickItem and not Qobject.
In the pro file remove
QT += declarative
and add
QT += quickHope that will help