PDA

View Full Version : Interface methods question



sincnarf
5th October 2007, 09:16
Here is an interface


#ifndef INTERFACES_H
#define INTERFACES_H
#include <QtPlugin>
#include <QtGui>
#include <QList>
class QImage;
class QString;
class QStringList;

class FilterInterface
{
public:
virtual ~FilterInterface(){}
virtual QStringList filters() const = 0;

virtual QImage filterImage(const QString &filter, const QImage &image,
QWidget *parent) = 0;
virtual QList<QImage> filterImageList(QString &filter, const QImage &image, QWidget *parent) = 0;

};
Q_DECLARE_INTERFACE(FilterInterface,
"com.iadfuq.sp.filterplugin.FilterInterface/1.0")

#endif


This is copied from the plug and paint example of Qt. Only difference is I added a method called filterImageList that must return a QList of QImage.

Now I am trying to use with


const QList<QImage> images = iFilter->filterImageList(action->text(),
pixmapItem->pixmap().toImage(), 0);


I get the error


mainwindow.cpp:1606: error: no matching function for call to ‘FilterInterface::filterImageList(QString, QImage, int)’
interfaces.h:20: note: candidates are: virtual QList<QImage> FilterInterface::filterImageList(QString&, const QImage&, QWidget*)


Is there something wrong with the way I declare QList<QImage> images?

marcel
5th October 2007, 09:21
Modify the interface to be:
FilterInterface::filterImageList(const QString&, const QImage&, QWidget*)

sincnarf
5th October 2007, 10:15
Ok that worked. What's the use of const and virtual keywords anyway...... so that I may learn....

marcel
5th October 2007, 10:20
const: http://en.wikipedia.org/wiki/Const_correctness
virtual: http://www.google.com/search?hl=en&q=c%2B%2B+polymorphism&btnG=Google+Search