Graphics view problem
-
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();
}@
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_OBJECTpublic:
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 -
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?