I made a change to scene object decleration in order to use it out of pushbuttons scope. I declare it as a private member of ResimOku object. create it in ResimOku decleration and use it in pushbutton events. With this the scope of scene object is ResimOku object scope.
Header file
#ifndef RESIMOKU_H
#define RESIMOKU_H
#include <QtGui>
#include <QMainWindow>
namespace Ui {
class ResimOku;
}
{
Q_OBJECT
public:
explicit ResimOku
(QWidget *parent
= 0);
~ResimOku();
private:
Ui::ResimOku *ui;
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
};
#endif // RESIMOKU_H
#ifndef RESIMOKU_H
#define RESIMOKU_H
#include <QtGui>
#include <QMainWindow>
namespace Ui {
class ResimOku;
}
class ResimOku : public QMainWindow
{
Q_OBJECT
public:
explicit ResimOku(QWidget *parent = 0);
~ResimOku();
private:
Ui::ResimOku *ui;
QGraphicsScene *scene;
private slots:
void on_pushButton_2_clicked();
void on_pushButton_clicked();
};
#endif // RESIMOKU_H
To copy to clipboard, switch view to plain text mode
CPP FILE
#include "resimoku.h"
#include "ui_resimoku.h"
ResimOku
::ResimOku(QWidget *parent
) : ui(new Ui::ResimOku)
{
ui->setupUi(this);
}
ResimOku::~ResimOku()
{
delete ui;
}
void ResimOku::on_pushButton_clicked()
{
scene->addPixmap(pixmap);
ui->view->setScene(scene);
ui->view->show();
}
void ResimOku::on_pushButton_2_clicked()
{
scene->addPixmap(pixmap);
ui->view->setScene(scene);
ui->view->show();
}
#include "resimoku.h"
#include "ui_resimoku.h"
ResimOku::ResimOku(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ResimOku)
{
ui->setupUi(this);
scene = new QGraphicsScene;
}
ResimOku::~ResimOku()
{
delete ui;
}
void ResimOku::on_pushButton_clicked()
{
QPixmap pixmap("C:/resim.jpg");
scene->addPixmap(pixmap);
ui->view->setScene(scene);
ui->view->show();
}
void ResimOku::on_pushButton_2_clicked()
{
QPixmap pixmap("C:/resim2.jpg");
scene->addPixmap(pixmap);
ui->view->setScene(scene);
ui->view->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks