denumbaone
24th February 2011, 21:24
I'm having a little trouble with QGraphicsView, i have a multiple file project and I have the main layout for the gui on dialog.cpp with all of the code for the GraphicsView in the MyGraphicsView.cpp file. I've gotten the GraphicsView to load onto the gui with no problem and it is completely funtional (can pan over and zoom in and out). The problem that I am having is that I have added two buttons onto the layout to also toggle the zooming in and out, and whenever I click on either one the program "unexpectedly finished." I have attached the important code below:
in MyGraphicsView.h
public slots:
virtual void zoomIn();
virtual void zoomOut();
private:
MyGraphicsView *graph;
MyGraphicsView *graphicsView;
in dialog.h
private:
MyGraphicsView *graphicsView;
MyGraphicsView *graph;
QPushButton *zoomInButton;
QPushButton *zoomOutButton;
in dialog.cpp
zoomInButton = new QPushButton(tr("+"));
zoomInButton->setFixedSize(50,30);
zoomOutButton = new QPushButton(tr("-"));
zoomOutButton->setFixedSize(50,30);
buttonLayout->addStretch();
buttonLayout->addWidget(zoomInButton);
buttonLayout->addWidget(zoomOutButton);
graph = new MyGraphicsView;
connect(zoomInButton, SIGNAL(clicked()), graph, SLOT(zoomIn()));
connect(zoomOutButton, SIGNAL(clicked()), graph, SLOT(zoomOut()));
and in MyGraphicsView.cpp
void MyGraphicsView::zoomIn(/*QKeyEvent * event*/)
{
cout << "Zoom in\n" << endl;
graphicsView->scale(2.0, 2.0);
}
void MyGraphicsView::zoomOut(/*QKeyEvent * event*/)
{
cout << "Zoom Out\n" << endl;
graphicsView->scale(0.5, 0.5);
}
As you can see, I have added a simple "cout" to make sure that the funtion is called, and it does. It's only when I click on the buttons that the program "unexpectedly finishes."
I apologize for the lengthy post, I only wanted to be as detailed as possible.
Thank you in advance for the help
in MyGraphicsView.h
public slots:
virtual void zoomIn();
virtual void zoomOut();
private:
MyGraphicsView *graph;
MyGraphicsView *graphicsView;
in dialog.h
private:
MyGraphicsView *graphicsView;
MyGraphicsView *graph;
QPushButton *zoomInButton;
QPushButton *zoomOutButton;
in dialog.cpp
zoomInButton = new QPushButton(tr("+"));
zoomInButton->setFixedSize(50,30);
zoomOutButton = new QPushButton(tr("-"));
zoomOutButton->setFixedSize(50,30);
buttonLayout->addStretch();
buttonLayout->addWidget(zoomInButton);
buttonLayout->addWidget(zoomOutButton);
graph = new MyGraphicsView;
connect(zoomInButton, SIGNAL(clicked()), graph, SLOT(zoomIn()));
connect(zoomOutButton, SIGNAL(clicked()), graph, SLOT(zoomOut()));
and in MyGraphicsView.cpp
void MyGraphicsView::zoomIn(/*QKeyEvent * event*/)
{
cout << "Zoom in\n" << endl;
graphicsView->scale(2.0, 2.0);
}
void MyGraphicsView::zoomOut(/*QKeyEvent * event*/)
{
cout << "Zoom Out\n" << endl;
graphicsView->scale(0.5, 0.5);
}
As you can see, I have added a simple "cout" to make sure that the funtion is called, and it does. It's only when I click on the buttons that the program "unexpectedly finishes."
I apologize for the lengthy post, I only wanted to be as detailed as possible.
Thank you in advance for the help