Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GraphicsView and scene
Forum Updated to NodeBB v4.3 + New Features

GraphicsView and scene

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MKSPulok
    wrote on last edited by
    #1

    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&#40;&#41;;
    

    }
    @

    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'

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MaQzma
      wrote on last edited by
      #2

      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.

      Mario.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        Moved to General, it's a Qt question. Also, the audience there should be much larger to answer your question.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mkuettler
          wrote on last edited by
          #4

          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
          @
          #include <QGraphicsRectItem>
          @

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved