Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. requestPixmap causes moc errors

requestPixmap causes moc errors

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.4k Views 3 Watching
  • 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 code in my makepix.h:

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

    It generates the following error message:
    moc_makepix.cpp:-1: error: undefined reference to MakePix::requestPixmap(QString const&, QSize*, QSize const&)' moc_makepix.cpp:-1: error: undefined reference to non-virtual thunk to MakePix::requestPixmap(QString const&, QSize*, QSize const&)'collect2.exe:-1: error: error: ld returned 1 exit status.
    If I comment out

    QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
    

    There is no error message and it builds and runs OK. How can I fix 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,

      You did not provide the implementation of that method hence the error. If you declare slots like that, you have to have at least an empty implementation of it.

      By the way, it's not a slot in the base case, there's not reason to change that in a subclass.

      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

        Hi,

        You did not provide the implementation of that method hence the error. If you declare slots like that, you have to have at least an empty implementation of it.

        By the way, it's not a slot in the base case, there's not reason to change that in a subclass.

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

        Hi @SGaist,
        I implemented requestPixmap and it is working now.

        Would you please explain what you meant by "it's not a slot in the base case, there's not reason to change that in a subclass."

        Thank you for your help.

        mrjjM 1 Reply Last reply
        0
        • G gabor53

          Hi @SGaist,
          I implemented requestPixmap and it is working now.

          Would you please explain what you meant by "it's not a slot in the base case, there's not reason to change that in a subclass."

          Thank you for your help.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @gabor53
          Hi
          You put requestPixmap function under slots:
          public slots:
          QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;

          but its not a slot in the base class ( base class is QQuickImageProvider in your case )

          its a virtual function one can override. ( as you did)
          and i assume its public.
          https://doc.qt.io/qt-5/qquickimageprovider.html#requestPixmap
          so its not a slot, so no reason to make it a slot in your class.

          G 1 Reply Last reply
          1
          • mrjjM mrjj

            @gabor53
            Hi
            You put requestPixmap function under slots:
            public slots:
            QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;

            but its not a slot in the base class ( base class is QQuickImageProvider in your case )

            its a virtual function one can override. ( as you did)
            and i assume its public.
            https://doc.qt.io/qt-5/qquickimageprovider.html#requestPixmap
            so its not a slot, so no reason to make it a slot in your class.

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

            Hi ,
            I removed requestPixmap from public slots. Thank you.
            How can I call

            QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
            

            Thank you.

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @gabor53 said in requestPixmap causes moc errors:

              QQuickImageProvider

              Its explained the docs for the class
              https://doc.qt.io/qt-5/qquickimageprovider.html#details

              You will use the name in the source statement
              Image { source: "image://MyImageProvider/Image.png" }

              note:

              • I removed requestPixmap from public slots
                Meaning you have moved it to public (non slot) section, i assume.
              G 1 Reply Last reply
              0
              • mrjjM mrjj

                @gabor53 said in requestPixmap causes moc errors:

                QQuickImageProvider

                Its explained the docs for the class
                https://doc.qt.io/qt-5/qquickimageprovider.html#details

                You will use the name in the source statement
                Image { source: "image://MyImageProvider/Image.png" }

                note:

                • I removed requestPixmap from public slots
                  Meaning you have moved it to public (non slot) section, i assume.
                G Offline
                G Offline
                gabor53
                wrote on last edited by
                #7

                @mrjj ,
                I understand now how QML will call QQuickimageProvider. But, how can I pass the image id(path) from QML?
                Thank you for your help.

                mrjjM 1 Reply Last reply
                0
                • G gabor53

                  @mrjj ,
                  I understand now how QML will call QQuickimageProvider. But, how can I pass the image id(path) from QML?
                  Thank you for your help.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @gabor53
                  Hi
                  in what way pass ?

                  • But, how can I pass the image id(path) from QML?

                  When you do
                  Image { source: "image://MyImageProvider/Image.png" }
                  i assume you will see Image.png as id.

                  G 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @gabor53
                    Hi
                    in what way pass ?

                    • But, how can I pass the image id(path) from QML?

                    When you do
                    Image { source: "image://MyImageProvider/Image.png" }
                    i assume you will see Image.png as id.

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

                    @mrjj,
                    Yes, but should I use a signal/slot to send the path from QML to C++ and call QQuickImageProvider from that slot?
                    Thank you.

                    mrjjM 1 Reply Last reply
                    0
                    • G gabor53

                      @mrjj,
                      Yes, but should I use a signal/slot to send the path from QML to C++ and call QQuickImageProvider from that slot?
                      Thank you.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #10

                      Hi
                      Nope. you register it.
                      "The QML engine invokes the appropriate image provider according to the providers that have been registered through QQmlEngine::addImageProvider()."
                      https://doc.qt.io/qt-5/qqmlengine.html#addImageProvider

                      Then when you do
                      Image { source: "image://MyImageProvider/Image.png" }
                      if you have registered as MyImageProvider , it will automatically be called.

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

                        Hi,

                        No, take a look again at the QQuickimageProvider documentation.

                        It shows how to use it from QML: Image { source: "image://myimageprovider/image.png" }

                        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,

                          No, take a look again at the QQuickimageProvider documentation.

                          It shows how to use it from QML: Image { source: "image://myimageprovider/image.png" }

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

                          @SGaist
                          Thank you. It works now.

                          1 Reply Last reply
                          0

                          • Login

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