Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
GraphicsView and scene
MKSPulok last edited by
why my this code is not running
int main(int argc, char *argv)
QApplication a(argc, argv);
QGraphicsScene *scene=new QGraphicsScene(0,0,400,400,&w);
QGraphicsItem *rect=new QGraphicsItem(50,50,100,100);
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'
MaQzma last edited by
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.
goetz last edited by
Moved to General, it's a Qt question. Also, the audience there should be much larger to answer your question.
mkuettler last edited by
In addition to what Mariø™ said: You need to include the header for the item you are using. So if you want to use QGraphicsRectItem you should