brianc
5th August 2010, 21:42
I'm new to Qt and trying to learn the Graphics and Animation frameworks. I created a simple app that using code pulled from the AnimatedTiles example app,but I cannot get it to compile.
The apps consist of main.cpp, posterimg.cpp and posterimg.h.
PosterImg is the same as the Pixmap class in the AnimatedTiles sample. I'm simply renamed it and moved it out of the main class. Unfortunately, now the app won't compile. Compiling produces the following errors:
posterimg.cpp:4: error: ISO C++ forbids declaration of 'PosterImage' with no type
posterimg.cpp:4: error: no 'int PosterImg::PosterImage(QPixmap&)' member function declared in class 'PosterImg'
Can anybody show me what I'm doing wrong?
Code for PosterImg.h
#ifndef POSTERIMG_H
#define POSTERIMG_H
#include <QPixmap>
#include <QGraphicsPixmapItem>
class PosterImg : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ WRITE setPos)
public:
PosterImg(QPixmap &pix);
};
#endif // POSTERIMG_H
Code for PosterImg.cpp
#include "posterimg.h"
PosterImg::PosterImage(QPixmap &pix)
: QObject(), QGraphicsPixmapItem(pix)
{
setCacheMode(DeviceCoordinateCache);
}
Code for main.cpp
#include <QtCore>
#include <QtGui>
#include "posterimg.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(uc1res);
QApplication app(argc, argv);
QGraphicsTextItem *textItem = new QGraphicsTextItem();
textItem->setHtml("<font color=\"black\"><b>Hello</b>");
textItem->setPos(100,50);
QPixmap myPix(":/images/kinetic.png");
PosterImg *myImg = new PosterImg(myPix);
QGraphicsScene scene;
scene.addItem(img);
scene.addItem(textItem);
scene.setBackgroundBrush(Qt::white);
QGraphicsView view;
view.setRenderHints(QPainter::Antialiasing);
view.setTransformationAnchor(QGraphicsView::NoAnch or);
view.setScene(&scene);
view.show();
view.setFocus();
return app.exec();
}
Brian
The apps consist of main.cpp, posterimg.cpp and posterimg.h.
PosterImg is the same as the Pixmap class in the AnimatedTiles sample. I'm simply renamed it and moved it out of the main class. Unfortunately, now the app won't compile. Compiling produces the following errors:
posterimg.cpp:4: error: ISO C++ forbids declaration of 'PosterImage' with no type
posterimg.cpp:4: error: no 'int PosterImg::PosterImage(QPixmap&)' member function declared in class 'PosterImg'
Can anybody show me what I'm doing wrong?
Code for PosterImg.h
#ifndef POSTERIMG_H
#define POSTERIMG_H
#include <QPixmap>
#include <QGraphicsPixmapItem>
class PosterImg : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ WRITE setPos)
public:
PosterImg(QPixmap &pix);
};
#endif // POSTERIMG_H
Code for PosterImg.cpp
#include "posterimg.h"
PosterImg::PosterImage(QPixmap &pix)
: QObject(), QGraphicsPixmapItem(pix)
{
setCacheMode(DeviceCoordinateCache);
}
Code for main.cpp
#include <QtCore>
#include <QtGui>
#include "posterimg.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(uc1res);
QApplication app(argc, argv);
QGraphicsTextItem *textItem = new QGraphicsTextItem();
textItem->setHtml("<font color=\"black\"><b>Hello</b>");
textItem->setPos(100,50);
QPixmap myPix(":/images/kinetic.png");
PosterImg *myImg = new PosterImg(myPix);
QGraphicsScene scene;
scene.addItem(img);
scene.addItem(textItem);
scene.setBackgroundBrush(Qt::white);
QGraphicsView view;
view.setRenderHints(QPainter::Antialiasing);
view.setTransformationAnchor(QGraphicsView::NoAnch or);
view.setScene(&scene);
view.show();
view.setFocus();
return app.exec();
}
Brian