C++ forbids declarations with no type
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
Code:
#ifndef POSTERIMG_H
#define POSTERIMG_H
#include <QPixmap>
#include <QGraphicsPixmapItem>
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ WRITE setPos
)
public:
};
#endif // POSTERIMG_H
Code for PosterImg.cpp
Code:
#include "posterimg.h"
PosterImg
::PosterImage(QPixmap &pix
){
setCacheMode(DeviceCoordinateCache);
}
Code for main.cpp
Code:
#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();
}
Brian
Re: C++ forbids declarations with no type
Well, error tells you all you need, and the error has nothing to with Qt, it is pure C++. Note that C++ in case sensitive.
Code:
#include "posterimg.h"
is not
Code:
#include "PosterImg.h"
and that you probably need. Also make sure that the path is right.
EDIT: and
Code:
PosterImg::PosterImage
should be
Code:
PosterImg::PosterImg
Re: C++ forbids declarations with no type
Typo: PosterImg::PosterImage(QPixmap &pix) correct should be PosterImg::PosterImg(...)
Re: C++ forbids declarations with no type
Thanks for the help. All that trouble caused by one typo.
Brian