GraphicsView and scene
-
why my this code is not running
@#include <QtGui/QApplication>
#include<QGraphicsView>
#include<QGraphicsScene>
//#include "MainWindow.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGarphicsView w;
QGraphicsScene *scene=new QGraphicsScene(0,0,400,400,&w);
scene->setBackgroundBrush(Qt::yellow);
w.setScene(scene);
QGraphicsItem *rect=new QGraphicsItem(50,50,100,100);
scene->addItem(rect);
scene->addText("Hello World");
w.show();return a.exec();
}
@it shows the following error
1.QGraphicsView was not declared in this scope.
2.expected ';' before 'w'
3. 'w ' was not declared in this scope
4.Invalid use of incomplete type 'struct QGraphicsItem'
5.forwared declaration of 'struct QGraphicsItem' -
Well, firstly you must change QGarphicsView for QGraphicsView, then you can not allocate an abstract object, QGraphicsItem is an abstract object, so you need to use QGraphicsRectItem, and if you want you can derive from QGraphicsItem. Pleace read "this":http://qt-project.org/doc/qt-4.8/qgraphicsitem.html information.