I am having big problems trying to put an gif-image into an application written in Qt. I have removed all the other code and right now I am just trying to make an image, nothing else. The image-widget is in the class RedBar and that is the only class I have. So here are my files:
Code:
bar.h
#ifndef __BAR_H__
#define __BAR_H__
#include <qwidget.h>
class QImage;
class RedBar : public QWidget {
public:
RedBar(const QString &filename, QWidget *parent, const char *name=0);
protected:
void paintEvent(QPaintEvent*);
private:
QImage *qimage;
};
#endif
Code:
bar.cc
#include <qimage.h>
#include <qpainter.h>
#include "bar.h"
RedBar::RedBar(const QString &filename, QWidget *parent, const char *name) : QWidget (parent, name) {
qimage = new QImage;
qimage->load(filename);
}
void RedBar::paintEvent(QPaintEvent*) {
QPainter qpainter(this);
qpainter.drawImage(0, 0, *qimage);
}
Code:
main.cc
#include <qapplication.h>
#include "bar.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
RedBar *bar1 = new RedBar(argv[1], 0);
a.setMainWidget(bar1);
bar1->show();
return a.exec();
}
Then I compile it and run:
The code compiles without problems but when I run the program I just get a big grey app with nothing in it. The image redbar.gif is a 10x10 image created in gimp. What am I doing wrong?