PDA

View Full Version : Plugin woes



stevey
23rd July 2006, 05:43
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:


#ifndef QTTIFFIMAGEHANDLER_H
#define QTTIFFIMAGEHANDLER_H

#include <QtGui/QImageIOHandler>
#include <QtCore/QIODevice>


class QtTiffImageHandler : public QImageIOHandler
{
public:
QtTiffImageHandler(QIODevice *device);
virtual ~QtTiffImageHandler();

static bool canRead(QIODevice *iod, QByteArray *subType);
bool canRead() const;

bool read(QImage *image);
bool write(const QImage &image);

QVariant option(ImageOption option) const;
void setOption(ImageOption option, const QVariant &value);
bool supportsOption(ImageOption option) const;

QByteArray name() const;


private:
int writeQuality;
QByteArray subType;

QByteArray parameters;

};

#endif // QTTIFFIMAGEHANDLER_H





#ifndef QTTIFFIMAGEPLUGIN_H
#define QTTIFFIMAGEPLUGIN_H

#include <QtGui/QImageIOPlugin>

class QtTiffImagePlugin : public QImageIOPlugin
{
public:

QImageIOHandler* create(QIODevice *device, const QByteArray &format = QByteArray()) const;
Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
QStringList keys() const;

};

#endif // QTTIFFIMAGEPLUGIN_H

The last line of my QtTiffImagePlugin cpp file is


Q_EXPORT_PLUGIN( QtTiffImagePlugin );


My test app has a QLabel and I set it's pixmap to a new QImage object:


QString imageFilename = QFileDialog::getOpenFileName(
this,
"Choose a file",
"D:/My Documents/Projects/Qt/QtTiffImageFormat/Debug",
"Images (*.png *.tif *.jpg *.jp2)");

if (!imageFilename.isEmpty())
{
QImage image(imageFilename);
if (image.isNull())
{
QMessageBox::information(this, tr("Image Viewer"), tr("Can't load '%1' mate.").arg(imageFilename));
return;
}
ui.lblImage->setPixmap(QPixmap::fromImage(image));


}


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

wysota
23rd July 2006, 07:04
What does your pro file look like?

stevey
23rd July 2006, 11:42
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:


TEMPLATE = lib
TARGET = QtTiffImageHandler
DESTDIR = $(QTDIR)/plugins/imageformats
CONFIG += plugin debug_and_release
INCLUDEPATH += ./GeneratedFiles \
./GeneratedFiles/$(ConfigurationName) \
./GeneratedFiles/release \
./GeneratedFiles \
c:/lib/libtiff/include

LIBS += -llibtiff -L"c:/lib/libtiff"
DEPENDPATH += .

MOC_DIR += ./GeneratedFiles/release
OBJECTS_DIR += release
UI_DIR += ./GeneratedFiles

HEADERS += ./QtTiffImagePlugin.h \
./qttiffimagehandler.h \
./tiffcodec.h

SOURCES += ./QtTiffImagePlugin.cpp \
./qttiffimagehandler.cpp \
./tiffcodec.cpp


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

wysota
23rd July 2006, 11:56
Try compiling manually from that .pro file (remember about the plugin and dll options) using qmake and nmake.

stevey
23rd July 2006, 12:56
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

jacek
23rd July 2006, 13:07
Try:
Q_EXPORT_PLUGIN2( QtTiffImageHandler, QtTiffImagePlugin );(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).

stevey
23rd July 2006, 14:42
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

wysota
23rd July 2006, 15:04
Check if QImageReader::supportedImageFormats() returns your image format.

stevey
24th July 2006, 01:30
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 :o .

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

Thanks wysota for your patience.