PDA

View Full Version : MyQImage Class



TeresaML
25th November 2009, 22:41
Hi,
I want to create my own Class of QImage type, but I've found an error:

Error C2664: 'QImage::QImage(const char *const [])' : can not convert parameter 1 from 'QWidget *' to 'const char *const []'


class MiQImage : public QImage
{
Q_OBJECT
public:
MiQImage(QWidget* parent);
};

MiQImage::MiQImage(QWidget* parent) : QImage(parent)
{

};

Any idea why it's wrong? Thanks!

vectori
25th November 2009, 23:01
Hi,
Error C2664: 'QImage::QImage(const char *const [])' : can not convert parameter 1 from 'QWidget *' to 'const char *const []'

MiQImage::MiQImage(QWidget* parent) : QImage(parent)
{

};


QImage takes e.g. filename as parameter not QWidget.
remove parent parameter from QImage constructor call.

like:
MiQImage::MiQImage(QWidget* parent) : QImage()
{

};

wysota
25th November 2009, 23:07
Could you explain why do you want to subclass QImage? I can hardly find a reason to do that.

TeresaML
26th November 2009, 09:25
I've have created my own class (MiQImage), with the class QImage in it, for two main reasons (correct me if I am wrong on any of these points, please):

- I want to instantiate a variable of the class MiQImage in the class MiQDialog. In this way, the variable will be visible for all the functions implemented in MiQDialog.
- I will add some features in the class MiQImage, which are not possible only with the class MiQImage (zoomin, zoomout,..).

I think it is a good solution, but I am newbie on this, so any suggestion or correction is very welcome.

Best Regards

wysota
26th November 2009, 09:52
QImage is nothing that is visible. It's just a structure of data tailored to hold an image. If you want to show an image on the screen, you will need QLabel or QGraphicsView with QGraphicsPixmapItem. If you want zooming and stuff, the latter might prove better - but you have to decide based on what you intend to use the image for.

TeresaML
26th November 2009, 10:17
When I said "......", I meant visible for the functions: the functions implemented may use the variable of the class MiQImage

wysota
26th November 2009, 10:22
Ah, ok... anyway I don't think subclassing QImage will do you much good here. Every operation you perform on the image will have to return a copy of the image anyway (you can't "zoom" an image, you have to crop it and scale it and both these operations return copies of the original image) so it might prove easier if you just placed your extra methods in the dialog class if that's the only place you will be accessing your images. If you insist on subclassing QImage, remember it is not a QObject, so no Q_OBJECT macro and no passing objects as parents. You also can't make QImage a QObject because QObjects can't be copied.