Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Non static image plugin

    General and Desktop
    4
    18
    5935
    Loading More Posts
    • 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.
    • S
      SteveBooth last edited by

      Has anyone been able to successfully create a previously unsupported image plugin type (i.e. not TIFF, JPG, GIFF, ICO, etc)?

      I ask because I believe there is a significant bug in the 'qmetaobject.cpp' kernel module.

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        If you refer to subclasses of [[Doc:QImageIOPlugin]], yes, these work. All the image format plugins delivered with Qt are based on this.

        If qmetaobject.cpp contained an error, I would suspect it to have popped up long before.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • S
          SteveBooth last edited by

          Well, all I can say is that I just created a plugin derived from QImageIOPlugin, and it;s DLL is found, and the 'keys' routine is called, but qmetaobject.cpp fails to recognize that it is a subclass of QImageIOPlugin. As a result, 'create' is never called, and it does not work.

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            Hard to say anything without seeing some code.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • S
              SteveBooth last edited by

              Alright. Here's the .h file:

              @#ifndef MSKPLUGIN_H
              #define MSKPLUGIN_H

              #include "mskplugin_global.h"
              #include "MskHandler.h"

              #include <qstringlist.h>
              #include <QImageIOPlugin>
              //#include <QtPlugin>

              QT_BEGIN_NAMESPACE

              class MskPlugin : public QImageIOPlugin
              {
              public:
              QStringList keys() const;
              Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
              QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;

              private:

              };

              #endif // MSKPLUGIN_H
              @

              and the .cpp:

              @#include "mskplugin.h"

              QStringList MskPlugin::keys() const
              {
              return QStringList() << QLatin1String("msk");
              }

              QImageIOPlugin::Capabilities MskPlugin::capabilities(
              QIODevice *device, const QByteArray &format) const
              {
              if (format == "msk")
              return Capabilities(CanRead);
              //return Capabilities(CanRead | CanWrite); Writing currently disabled.

              if (!(format.isEmpty() && device->isOpen()))
                  return 0;
              
              Capabilities cap;
              

              if (device->isReadable() && device->peek(4) == "MSK2")
              cap |= CanRead;

              /* Currently, disable writing.
              if (device->isWritable())
              cap |= CanWrite;
              */

              return cap;
              

              }

              QImageIOHandler *MskPlugin::create(QIODevice *device, const QByteArray &format) const
              {
              QImageIOHandler *handler = new MskHandler;
              handler->setDevice(device);
              handler->setFormat(format);
              return handler;
              }

              Q_EXPORT_PLUGIN2(mskPlugin, MskPlugin)

              QT_END_NAMESPACE
              @

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                The class declaration in the header file (.h) is missing the Q_OBJECT macro.

                @
                QT_BEGIN_NAMESPACE

                class MskPlugin : public QImageIOPlugin
                {
                Q_OBJECT
                public:
                QStringList keys() const;
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply Reply Quote 0
                • S
                  SteveBooth last edited by

                  Tried that; it had no effect. And, none of the example plugins have Q_OBJECT. For example, here's the plugin def for the 'ICO' file type:

                  @class QICOPlugin : public QImageIOPlugin
                  {
                  public:
                  QStringList keys() const;
                  Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
                  QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const;
                  };
                  @

                  1 Reply Last reply Reply Quote 0
                  • G
                    goetz last edited by

                    The code looks ok so far. I just tried with my own plugin, it gets called and I don't get any errors (despite my actual read method not being implemented yet and thus returning and empty image :) )

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply Reply Quote 0
                    • S
                      SteveBooth last edited by

                      Interesting. Can you give me some more info about your config? Version? iDE you used, What file type you defined, please. Mine is 4.7.4 64 bit and VS 2010

                      1 Reply Last reply Reply Quote 0
                      • G
                        goetz last edited by

                        I'm using the Mac, Qt 4.8.0. But this shouldn't be a problem.

                        Do you get any output on the console? Some warnings, etc.?

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply Reply Quote 0
                        • S
                          SteveBooth last edited by

                          Yes, actually:

                          QObject::moveToThread: Current thread (0x1f2a7b0) is not the object's thread (0x398450).
                          Cannot move to target thread (0x1f2a7b0)

                          Although, I cant, for the life of me, see how it relates.

                          1 Reply Last reply Reply Quote 0
                          • G
                            goetz last edited by

                            So, you have threads involved. That complicates things.

                            As a first step: Cut down your application to just the imageformat plugin and a very, very simple test application. No threads, no fancy GUI. Just a dialog containing a label and three lines to set an image on the label - setPixmap(QPixmap::fromImage(xxx)). Nothing more.

                            If that works, move on to a bigger project. If not, feel free to come back here, of course :)

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply Reply Quote 0
                            • S
                              SteveBooth last edited by

                              Ummm... Well first, I don't use threads in my app -- that's why the message seemed strange. And secondly, your suggestion is exactly where I am, now. Here is my app currently (minus the 'main.cpp which is the generic app startup for a single dialog):

                              @#include "qimsktest.h"

                              #include "qfileinfo.h"

                              #include "qpluginloader.h"
                              #include "qlibrary.h"
                              #include "qimageiohandler.h"

                              QIMskTest::QIMskTest(QWidget *parent, Qt::WFlags flags)
                              : QMainWindow(parent, flags)
                              {
                              ui.setupUi(this);

                              QString mskFp("...0012.msk");

                              QImage* mskImg = new QImage(mskFp);

                              QPixmap mskPmp = QPixmap::fromImage(*mskImg);

                              ui.mskImg->setPixmap(sMskPmp);
                              }

                              QIMskTest::~QIMskTest()
                              {

                              }
                              @

                              1 Reply Last reply Reply Quote 0
                              • S
                                SteveBooth last edited by

                                The moveToThread error message is caused by this code, at line 239 in 'qfactoryloader.cpp:

                                @ obj->moveToThread(QCoreApplicationPrivate::mainThread());@

                                Which, in turn is called by line 292 in qimagereader.cpp:

                                @ QImageIOPlugin *plugin = qobject_cast<QImageIOPlugin *>(l->instance(QString::fromLatin1(suffix)));
                                @

                                It's trying to get a plugin pointer for my DLL class so it can call the 'create' method. The thread error causes the above line to return zero for 'plugin', and hence, none of my other plugin classes gets called.

                                1 Reply Last reply Reply Quote 0
                                • G
                                  goetz last edited by

                                  Do you have another library in use which sneaks in the secondary thread? Do you load the plugin manually or do you leave it delegated to the image I/O system?

                                  My plugin is not yet ready to be published, so I cannot offer something to test and compare for you.

                                  http://www.catb.org/~esr/faqs/smart-questions.html

                                  1 Reply Last reply Reply Quote 0
                                  • S
                                    SteveBooth last edited by

                                    No, what you see is what I have. There's just the one form, with the single label on it. I have no other threads defined, and I don't use another library. I do not load the plugin manually; QT loads is automatically.

                                    1 Reply Last reply Reply Quote 0
                                    • N
                                      Nmut last edited by

                                      Hi guys

                                      Sorry to "up" this old thread...

                                      Steve, did you solve your problem?
                                      I have the same message with my custom image plugin. the only thing I had found is that there is some mismatch with Qt versions (4.7.4 and 4.8.0 installed...). And my plugin is nether recognised (QImageReader::supportedImageFormats does not return my image format).

                                      Regards,
                                      Nmut.

                                      1 Reply Last reply Reply Quote 0
                                      • K
                                        KarolDuke last edited by

                                        Hello

                                        This fantastic Flip Image Plugin lets me design the back of my photo to complement the text I put there. It offers a great choice of colors and fonts. Way to go Flip Image!

                                        http://wordpress.org/extend/plugins/wp-flip-image-free

                                        Thanks.

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post