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. Graphics view problem
Qt 6.11 is out! See what's new in the release blog

Graphics view problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.1k 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 properly

    i've the following main.cpp
    @#include <QtGui/QApplication>
    #include "MainWindow.h"
    #include "EERTView.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    EERTView widget;
    // MainWindow w;

    widget.show();
    
    return a.exec&#40;&#41;;
    

    }@

    the MainWindow.cpp

    @#include "MainWindow.h"
    #include "ui_MainWindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    this->setWindowTitle("EERTInstructor");

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    MainWindow.h

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    //#include <QGraphicsView>
    //#include <QGraphicsScene>
    //#include <QGraphicsItem>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;
    };

    #endif // MAINWINDOW_H
    @

    EERTView.cpp

    @#include "EERTView.h"

    EERTView::EERTView(QObject *parent) :
    QGraphicsView(parent)
    {
    // making a scene on the application
    // QGraphicsScene scene;
    QGraphicsScene *scene = new QGraphicsScene(this);

       //adding some text to the scene
       scene.addText("Hello, world!", QFont("Times", 20, QFont::Bold));
       scene->set.addText("Hello, world!", QFont("Times", 20, QFont::Bold));
       //assigning that scene to the view
       QGraphicsView view(&scene);
       setScene(view);
    

    }
    @

    and EERTView.h

    @#ifndef EERTVIEW_H
    #define EERTVIEW_H

    #include <QGraphicsView>
    #include <QGraphicsScene>
    #include <QGraphicsItem>

    class EERTView : public QGraphicsView
    {
    Q_OBJECT
    public:
    explicit EERTView(QObject *parent = 0);

    signals:

    public slots:

    };

    #endif // EERTVIEW_H@

    I'm new in Qt plz anyone help .Inform me what do do with that code and how to make that working
    It give me the erro
    1.call of overloaded 'QGraphicsView(QObject *&)' is ambigous

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi,

      there are some errors:

      @
      EERTView::EERTView(QObject *parent) :
      QGraphicsView(parent)
      {
      // making a scene on the application
      // QGraphicsScene scene;
      QGraphicsScene *scene = new QGraphicsScene(this);

         //adding some text to the scene
         scene.addText("Hello, world!", QFont("Times", 20, QFont::Bold));       // <-- error 1
         scene->set.addText("Hello, world!", QFont("Times", 20, QFont::Bold));// <-- error 3
         //assigning that scene to the view
         QGraphicsView view(&scene);              // <-- error 2
         setScene(view);
      

      }
      @

      error 1 is that you call a not existing object

      error 2 is that you create an object on the stack, add it as widget to the parent. After exiting the function, the object is destroyed again.

      error 3: What is this set in the call?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      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