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>
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ WRITE setPos
)
public:
};
#endif // 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
To copy to clipboard, switch view to plain text mode
Code for PosterImg.cpp
#include "posterimg.h"
PosterImg
::PosterImage(QPixmap &pix
){
setCacheMode(DeviceCoordinateCache);
}
#include "posterimg.h"
PosterImg::PosterImage(QPixmap &pix)
: QObject(), QGraphicsPixmapItem(pix)
{
setCacheMode(DeviceCoordinateCache);
}
To copy to clipboard, switch view to plain text mode
Code for main.cpp
#include <QtCore>
#include <QtGui>
#include "posterimg.h"
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(uc1res);
textItem->setHtml("<font color=\"black\"><b>Hello</b>");
textItem->setPos(100,50);
QPixmap myPix
(":/images/kinetic.png");
PosterImg *myImg = new PosterImg(myPix);
scene.addItem(img);
scene.addItem(textItem);
scene.setBackgroundBrush(Qt::white);
view.
setRenderHints(QPainter::Antialiasing);
view.setScene(&scene);
view.show();
view.setFocus();
return app.exec();
}
#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::NoAnchor);
view.setScene(&scene);
view.show();
view.setFocus();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Brian
Bookmarks