Results 1 to 4 of 4

Thread: Problem with Graphics view

  1. #1
    Join Date
    Feb 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Problem with Graphics view

    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

    Qt Code:
    1. public slots:
    2. virtual void zoomIn();
    3. virtual void zoomOut();
    4.  
    5. private:
    6. MyGraphicsView *graph;
    7. MyGraphicsView *graphicsView;
    To copy to clipboard, switch view to plain text mode 

    in dialog.h

    Qt Code:
    1. private:
    2. MyGraphicsView *graphicsView;
    3. MyGraphicsView *graph;
    4. QPushButton *zoomInButton;
    5. QPushButton *zoomOutButton;
    To copy to clipboard, switch view to plain text mode 

    in dialog.cpp

    Qt Code:
    1. zoomInButton = new QPushButton(tr("+"));
    2. zoomInButton->setFixedSize(50,30);
    3. zoomOutButton = new QPushButton(tr("-"));
    4. zoomOutButton->setFixedSize(50,30);
    5. buttonLayout->addStretch();
    6. buttonLayout->addWidget(zoomInButton);
    7. buttonLayout->addWidget(zoomOutButton);
    8.  
    9. graph = new MyGraphicsView;
    10.  
    11. connect(zoomInButton, SIGNAL(clicked()), graph, SLOT(zoomIn()));
    12. connect(zoomOutButton, SIGNAL(clicked()), graph, SLOT(zoomOut()));
    To copy to clipboard, switch view to plain text mode 

    and in MyGraphicsView.cpp

    Qt Code:
    1. void MyGraphicsView::zoomIn(/*QKeyEvent * event*/)
    2. {
    3. cout << "Zoom in\n" << endl;
    4. graphicsView->scale(2.0, 2.0);
    5. }
    6.  
    7. void MyGraphicsView::zoomOut(/*QKeyEvent * event*/)
    8. {
    9. cout << "Zoom Out\n" << endl;
    10. graphicsView->scale(0.5, 0.5);
    11. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with Graphics view

    Do you initialize both graphicsView and both graph (total of four) variables?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem with Graphics view

    I have posted everything I have in my program that is related to the problem.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with Graphics view

    So fix your program by initializing all four views properly. Your program crashes due to dereferencing dangling pointers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Problem about Graphics View Framework
    By FinderCheng in forum Qt Programming
    Replies: 5
    Last Post: 3rd November 2009, 08:16
  2. Problem with big visualization in graphics view
    By ProTonS in forum Qt Programming
    Replies: 2
    Last Post: 15th September 2009, 17:53
  3. Problem with Graphics View Framework
    By Disperato in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 20:44
  4. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  5. graphics view FitInView problem
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 10:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.