Results 1 to 9 of 9

Thread: Plugin woes

  1. #1
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Plugin woes

    Hi,

    I started writing an image format plugin about 12 months ago for Qt 4.
    I never quite managed to get the thing working though.
    I now need to consolidate the issue and get things working for an upcoming project though.
    So I found the TiffIO plugin from the Artis website.
    The only problem with that library is the latest version won't compile and I haven't yet received feedback from the author.
    Given that I also plan to get a few plugins going for other image formats, I figured that I'd just finally get the nearly finished Tiff one going.

    So, I used the jpeg 2000 one as a base, I used this one because I tested it and it compiled and ran without any problems.
    My output path from VS is $(QTDIR)/plugins/imageformats and I know the file is being picked up because when I select a tiff file from my test gui application the dll's are locked and I can't delete them. I understand though that this doesn't mean it was recognised as a valid plugin.

    So here's the class headers I've implemented:
    Qt Code:
    1. #ifndef QTTIFFIMAGEHANDLER_H
    2. #define QTTIFFIMAGEHANDLER_H
    3.  
    4. #include <QtGui/QImageIOHandler>
    5. #include <QtCore/QIODevice>
    6.  
    7.  
    8. class QtTiffImageHandler : public QImageIOHandler
    9. {
    10. public:
    11. QtTiffImageHandler(QIODevice *device);
    12. virtual ~QtTiffImageHandler();
    13.  
    14. static bool canRead(QIODevice *iod, QByteArray *subType);
    15. bool canRead() const;
    16.  
    17. bool read(QImage *image);
    18. bool write(const QImage &image);
    19.  
    20. QVariant option(ImageOption option) const;
    21. void setOption(ImageOption option, const QVariant &value);
    22. bool supportsOption(ImageOption option) const;
    23.  
    24. QByteArray name() const;
    25.  
    26.  
    27. private:
    28. int writeQuality;
    29. QByteArray subType;
    30.  
    31. QByteArray parameters;
    32.  
    33. };
    34.  
    35. #endif // QTTIFFIMAGEHANDLER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef QTTIFFIMAGEPLUGIN_H
    2. #define QTTIFFIMAGEPLUGIN_H
    3.  
    4. #include <QtGui/QImageIOPlugin>
    5.  
    6. class QtTiffImagePlugin : public QImageIOPlugin
    7. {
    8. public:
    9.  
    10. QImageIOHandler* create(QIODevice *device, const QByteArray &format = QByteArray()) const;
    11. Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
    12. QStringList keys() const;
    13.  
    14. };
    15.  
    16. #endif // QTTIFFIMAGEPLUGIN_H
    To copy to clipboard, switch view to plain text mode 
    The last line of my QtTiffImagePlugin cpp file is
    Qt Code:
    1. Q_EXPORT_PLUGIN( QtTiffImagePlugin );
    To copy to clipboard, switch view to plain text mode 

    My test app has a QLabel and I set it's pixmap to a new QImage object:
    Qt Code:
    1. QString imageFilename = QFileDialog::getOpenFileName(
    2. this,
    3. "Choose a file",
    4. "D:/My Documents/Projects/Qt/QtTiffImageFormat/Debug",
    5. "Images (*.png *.tif *.jpg *.jp2)");
    6.  
    7. if (!imageFilename.isEmpty())
    8. {
    9. QImage image(imageFilename);
    10. if (image.isNull())
    11. {
    12. QMessageBox::information(this, tr("Image Viewer"), tr("Can't load '%1' mate.").arg(imageFilename));
    13. return;
    14. }
    15. ui.lblImage->setPixmap(QPixmap::fromImage(image));
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    At the beginning of every function I'm opening a new text file and writing a message to it so I can track if any of my plugin's functions are being called, but none of these files are being created so I'm assuming that my plugin simply isn't even being queried for it's formats / capabilites.
    Can anyone familiar with this process please let me know if I'm missing some obvious step?
    Or even a not so obvious one

    Thanks,

    Steve York

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin woes

    What does your pro file look like?

  3. #3
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin woes

    Hi,

    I created this entire project within Visual Studio.
    Since your reply though I was thinkng about .pro files then remembered that you need to specify 'plugin'.
    So I created a .pro from within VS and noticed the CONFIG += plugin wasn't specified.
    I thought that might have been the problem.

    So I hand crafted a pro as follows:
    Qt Code:
    1. TEMPLATE = lib
    2. TARGET = QtTiffImageHandler
    3. DESTDIR = $(QTDIR)/plugins/imageformats
    4. CONFIG += plugin debug_and_release
    5. INCLUDEPATH += ./GeneratedFiles \
    6. ./GeneratedFiles/$(ConfigurationName) \
    7. ./GeneratedFiles/release \
    8. ./GeneratedFiles \
    9. c:/lib/libtiff/include
    10.  
    11. LIBS += -llibtiff -L"c:/lib/libtiff"
    12. DEPENDPATH += .
    13.  
    14. MOC_DIR += ./GeneratedFiles/release
    15. OBJECTS_DIR += release
    16. UI_DIR += ./GeneratedFiles
    17.  
    18. HEADERS += ./QtTiffImagePlugin.h \
    19. ./qttiffimagehandler.h \
    20. ./tiffcodec.h
    21.  
    22. SOURCES += ./QtTiffImagePlugin.cpp \
    23. ./qttiffimagehandler.cpp \
    24. ./tiffcodec.cpp
    To copy to clipboard, switch view to plain text mode 

    If I create a .vcproj file using qmake or "Qt -> Open Solution from pro file..." in VS I get a project that compiles without modification.
    But, then if I export to a new .pro, the plugin option isn't set.
    I'm guessing the option simply ensures that a dll is created and no other specific flags are defined.

    This .pro still doesn't fix the problem.
    I'm not getting of my debugging files dumed to c:/

    Any thoughts?

    --
    Steve

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin woes

    Try compiling manually from that .pro file (remember about the plugin and dll options) using qmake and nmake.

  5. #5
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin woes

    I just compiled both the debug and release version, but when I run my gui app (rebuilt) it still doesn't dump my test text files to c:/

    The problem is that I'm not even sure what's supposed to be happening.
    I'm not actually confident that my code is going to allow the reading of tiff file as there are issues with it and I haven't been able to step through it yet.
    Am I right in assuming that one of the methods listed in my first post should be entered at the loading stage?


    --
    Steve

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin woes

    Try:
    Qt Code:
    1. Q_EXPORT_PLUGIN2( QtTiffImageHandler, QtTiffImagePlugin );
    To copy to clipboard, switch view to plain text mode 
    (first parameter must match the file name).

    Also make sure that Qt can find libtiff (for example copy it to the same directory where your executable is).

  7. #7
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin woes

    Why should Qt need to be able to find libtiff?
    This ImageIOPlugin statically links to libtiff and wraps all the functionality.
    Surely all Qt's plugin loader needs access to is the plugin dll / lib ?

    I thought it might be prudent to attach some source code.
    TiffHandlerTest is a gui app which I've been using to try to debug this plugin.
    It's just got a QLabel and a Button to alow you to select an image to load.

    I couldn't attach libtiff but I have a win32 build of version 3.8.2 available at http://funkydung.toythieves.com/libtiff.zip

    I'd be grateful if anyone could take some time to have a look as I'm just utterly lost, and haven't a clue what to consider next.

    Thanks,

    Steve
    Attached Files Attached Files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin woes

    Check if QImageReader::supportedImageFormats() returns your image format.

  9. #9
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin woes

    QImageReader::supportedImageFormats() returns a list of the available plugins, but mine isn't listed.
    Mind you, I'm now getting my test files writing so I now know that my dll is at least being checked.
    Man, you know, if I had half a brain I'd be dangerous.
    Let me just say that I've been c#'d.
    My day job is .net development primarily in C# and it's obviously affected my brain.
    I'd persoanlly like to remove the attachments from my previous mail because it's all just too .

    Ho hum.
    I'll post a follow up if I get this beast working.
    Hopefully there won't be any further problems

    Thanks wysota for your patience.
    Last edited by stevey; 24th July 2006 at 02:43.

Similar Threads

  1. Testing a custom Plugin
    By maluta in forum Qt Programming
    Replies: 5
    Last Post: 31st October 2006, 15:09
  2. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  3. Application plugin on windows
    By Eyee in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2006, 17:36
  4. Size of a plugin widget in designer
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2006, 13:29
  5. Managing widget plugin in Qt Designer
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 31st January 2006, 09:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.