rakefet
27th February 2014, 21:04
Hi,
I built a project that displays 2 images on a graphics view widget. At first, I created a scene and displayed the images with QPixmap pix("<file_name>"), where <file_name> is hard coded. My second try is to pass the images file name through the main window.
In mainwindow.h:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QString image1, QString image2, QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
in mainwindow.cpp:
MainWindow::MainWindow(QString image1, QString image2, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//qDebug()<<image1;
//qDebug()<<image2;
ui->widget1->setImageFileName(image1);
ui->widget2->setImageFileName(image2);
ui->setupUi(this);
}
widget1 and widget2 are from class MyGraphicsView.
in mygraphicsview.h:
class MyGraphicsView : public QGraphicsView
{
public:
MyGraphicsView(QWidget* parent = NULL);
QString ImageFileName;
QString getImageFileName();
void setImageFileName(QString ImageFileName);
};
in mygraphicsview.cpp:
QPixmap pix(this->getImageFileName());
.
.
.
.
void MyGraphicsView::setImageFileName(QString FileName)
{
MyGraphicsView::ImageFileName = FileName;
}
QString MyGraphicsView::getImageFileName()
{
QString FileName = MyGraphicsView::ImageFileName;
return FileName;
}
Running the project I am getting the error:
Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
and it crashes.
It looks like this is not the way to pass parameters from mainwindow to the child widget.
Any other way to do it?
Thanks,
I built a project that displays 2 images on a graphics view widget. At first, I created a scene and displayed the images with QPixmap pix("<file_name>"), where <file_name> is hard coded. My second try is to pass the images file name through the main window.
In mainwindow.h:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QString image1, QString image2, QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
in mainwindow.cpp:
MainWindow::MainWindow(QString image1, QString image2, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//qDebug()<<image1;
//qDebug()<<image2;
ui->widget1->setImageFileName(image1);
ui->widget2->setImageFileName(image2);
ui->setupUi(this);
}
widget1 and widget2 are from class MyGraphicsView.
in mygraphicsview.h:
class MyGraphicsView : public QGraphicsView
{
public:
MyGraphicsView(QWidget* parent = NULL);
QString ImageFileName;
QString getImageFileName();
void setImageFileName(QString ImageFileName);
};
in mygraphicsview.cpp:
QPixmap pix(this->getImageFileName());
.
.
.
.
void MyGraphicsView::setImageFileName(QString FileName)
{
MyGraphicsView::ImageFileName = FileName;
}
QString MyGraphicsView::getImageFileName()
{
QString FileName = MyGraphicsView::ImageFileName;
return FileName;
}
Running the project I am getting the error:
Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly
and it crashes.
It looks like this is not the way to pass parameters from mainwindow to the child widget.
Any other way to do it?
Thanks,