Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ImageProvider error

ImageProvider error

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 783 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have the following imageprovider setup:
    Main.qml:

    import Felgo 3.0
    import QtQuick 2.11
    import QtQuick.Dialogs 1.2
    
    App {
        id: app
    
        NavigationStack {
    
            Page {
                title: qsTr("Image Converter")
    
                IconButton {
                    id: enlarge
                    visible: false
                    color: "blue"
                    icon: IconType.arrowsalt
                    anchors.baseline: button.baseline
                    anchors.right: button.left
    
                    onClicked: {
                        PictureViewer.show(app, image.source)
                    }
                }
    
                AppButton {
                    id: button
    
                    anchors.horizontalCenter: imageViewer.horizontalCenter
                    anchors.bottom: imageViewer.top
                    text: "Choose Image"
                    onClicked: {
                        nativeUtils.displayImagePicker("Choose the Friend's Image")
                    }
                }
    
                Rectangle {
                    id: imageViewer
                    width: 250
                    height: 250
                    anchors.centerIn: parent
    
                    AppImage {
                        id: image
                        onStatusChanged: if (image.status == Image.Ready)
                                             enlarge.visible = true
                        anchors.fill: parent
                        width: 250
                        height: 250
                        autoTransform: true
                        fillMode: Image.PreserveAspectFit
                    }
                }
    
                Connections {
                    target: nativeUtils
    
                    onImagePickerFinished: {
                        if (accepted) {
                            var path
                            image.source = "image://pix/path"
    
                            console.log("The path in main.qml: ", path)
                        }
                    }
                }
            }
        }
    }
    
    

    MakePix.h:

    #ifndef MAKEPIX_H
    #define MAKEPIX_H
    
    #include <QObject>
    #include <QQuickImageProvider>
    #include <QString>
    
    class MakePix : public QObject, public QQuickImageProvider
    {
    	Q_OBJECT
    public:
    	MakePix()
    		: QQuickImageProvider(QQuickImageProvider::Pixmap)
    	{}
    
    	QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
    };
    
    #endif // MAKEPIX_H
    
    

    MakePix.cpp:

    #include "makepix.h"
    #include <QDebug>
    #include <QPixmap>
    
    QPixmap MakePix::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize)
    {
    	QPixmap pixmap(id);
    	int height = pixmap.height();
    	int width = pixmap.width();
    	if(size)
    	{
    		*size = QSize(width, height);
    	}
    
    	QPixmap pixmap2(requestedSize.width() > 0 ? requestedSize.width() : width,
    					requestedSize.height() > 0 ? requestedSize.height() : height);
    
    	return pixmap2;
    }
    
    

    Main.cpp:

    #include "makepix.h"
    #include <FelgoApplication>
    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QQmlContext>
    #include <QQuickView>
    
    int main(int argc, char* argv[])
    {
    	QApplication app(argc, argv);
    	FelgoApplication felgo;
    
    	// Use platform-specific fonts instead of Felgo's default font
    	felgo.setPreservePlatformFonts(true);
    
    	QQmlApplicationEngine engine;
    	felgo.initialize(&engine);
    
    	felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
    
    	QQuickView view;
    	view.engine()->addImageProvider(QLatin1String("pix"), new MakePix);
    	view.setSource(QUrl::fromLocalFile(QStringLiteral("Main.qml")));
    	view.show();
    
    	engine.load(QUrl(felgo.mainQmlFileName()));
    
    	return app.exec();
    }
    
    

    It builds without any problems, but when I run it it gives the following error message:
    "Main.qml:43:17: QML AppImage: Invalid image provider: image://pix/path".
    How can I correct this error?
    Thank you for your help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I haven't used Felgo but one thing that strikes me is that you might be using two different engines. One of which you didn't configure to use your image provider.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        I haven't used Felgo but one thing that strikes me is that you might be using two different engines. One of which you didn't configure to use your image provider.

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @SGaist ,
        WHich one is the unconfigured one?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Well... The one you don't call addImageProvider on.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          2
          • SGaistS SGaist

            Well... The one you don't call addImageProvider on.

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            @SGaist ,
            I made some changes:

            #include "makepix.h"
            #include <FelgoApplication>
            #include <QApplication>
            #include <QQmlApplicationEngine>
            #include <QQmlContext>
            #include <QQuickView>
            
            int main(int argc, char* argv[])
            {
            	QApplication app(argc, argv);
            	FelgoApplication felgo;
            
            	felgo.setPreservePlatformFonts(true);
            
            	QQmlApplicationEngine engine;
            	felgo.initialize(&engine);
            
            	felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
            
            	MakePix* myMakePix = new MakePix();
            
            	engine.addImageProvider("pix", myMakePix);
            
            	engine.load(QUrl(felgo.mainQmlFileName()));
            
            	return app.exec();
            }
            
            

            Now the image provider works. Thank you for your help.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved