I've made changes recommended by Talei, but still no luck all I can get is "Program finished unexpectedly, exited with code 0". There is no other errors in compilation. Any ideas why that's no working ? new code :
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QPushButton>
#include <paintarea.h>
namespace Ui
{
class mainwindow;
}
{
Q_OBJECT
public:
~mainwindow();
private:
Ui::mainwindow *ui;
paintarea *parea;
public slots:
void send_signal();
private slots:
void updateLabel(int);
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QPushButton>
#include <paintarea.h>
namespace Ui
{
class mainwindow;
}
class mainwindow : public QMainWindow
{
Q_OBJECT
public:
mainwindow(QWidget *parent = 0);
~mainwindow();
private:
Ui::mainwindow *ui;
QPushButton *button;
paintarea *parea;
public slots:
void send_signal();
private slots:
void updateLabel(int);
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow
::mainwindow(QWidget *parent
){
ui->setupUi(this);
button = ui->button;
paintarea *parea;
connect (button,SIGNAL (clicked()),this,SLOT (send_signal()));
connect (parea, SIGNAL(mySignal(int)), this, SLOT(updateLabel(int)));
}
mainwindow::~mainwindow()
{
delete ui;
}
void mainwindow::send_signal()
{
ui->paint_space->load_image("/home/laabor/Pictures/test.jpeg");
}
void mainwindow::updateLabel(int w)
{
this
->ui
->label
->setText
(QVariant(w
).
toString());
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow::mainwindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::mainwindow)
{
ui->setupUi(this);
button = new QPushButton;
button = ui->button;
paintarea *parea;
connect (button,SIGNAL (clicked()),this,SLOT (send_signal()));
connect (parea, SIGNAL(mySignal(int)), this, SLOT(updateLabel(int)));
}
mainwindow::~mainwindow()
{
delete ui;
}
void mainwindow::send_signal()
{
ui->paint_space->load_image("/home/laabor/Pictures/test.jpeg");
}
void mainwindow::updateLabel(int w)
{
this->ui->label->setText(QVariant(w).toString());
}
To copy to clipboard, switch view to plain text mode
paintarea.h
#ifndef PAINTAREA_H
#define PAINTAREA_H
#include <QWidget>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
{
Q_OBJECT
public:
void load_image
(const QString &fileName
);
protected:
bool status;
signals:
void mySignal(int);
};
#endif // PAINTAREA_H
#ifndef PAINTAREA_H
#define PAINTAREA_H
#include <QWidget>
#include <QPainter>
#include <QPixmap>
#include <QLabel>
class paintarea : public QWidget
{
Q_OBJECT
public:
paintarea(QWidget *parent = 0);
void load_image(const QString &fileName);
protected:
void paintEvent(QPaintEvent *event);
QPixmap image;
QLabel label;
bool status;
signals:
void mySignal(int);
};
#endif // PAINTAREA_H
To copy to clipboard, switch view to plain text mode
paintarea.cpp
#include "paintarea.h"
paintarea
::paintarea (QWidget *parent
) :{
status = false ;
}
{
if(status)
{
painter.drawPixmap(0,0,image);
}
}
void paintarea
::load_image(const QString &fileName
) {
image.load(fileName);
status = true ;
update();
emit mySignal(image.width());
}
#include "paintarea.h"
paintarea::paintarea (QWidget *parent) :
QWidget(parent)
{
status = false ;
}
void paintarea::paintEvent(QPaintEvent *event)
{
if(status)
{
QPainter painter(this);
painter.drawPixmap(0,0,image);
}
}
void paintarea::load_image(const QString &fileName)
{
image.load(fileName);
status = true ;
update();
emit mySignal(image.width());
}
To copy to clipboard, switch view to plain text mode
Bookmarks