Results 1 to 13 of 13

Thread: Error code after inheriting QGraphicsView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Location
    Warsaw, Poland
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Error code after inheriting QGraphicsView

    Hi everyone!

    I have some problem with QGraphicsView. I want to create a program that will allow me to draw rectangles on loaded image. I have created my own GraphicsView class that inherits from QGraphicsView and I have overloaded QGraphicsView::mouseReleaseEvent to get the mouse position. I also added 'Widget' from Qt Creator to my form and replaced it with my class. It works fine until I close the window. After that I get an error code (-1073741819). Debugger shows segmentation fault in function QScopedPointer (no idea why). Probably I have to call some function, but I don't know which one and where. I will show you my code (only .cpp). Tell me if you need the header files.

    I hope you understand what I mean Could you help me?

    MainWindow class:
    Qt Code:
    1. #include "MainWindow.h"
    2. #include "ui_MainWindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::MainWindow)
    5. {
    6. ui->setupUi(this);
    7. ui->widget->setScene(&scene);
    8.  
    9. connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close()));
    10. connect(ui->loadButton, SIGNAL(clicked()), this, SLOT(loadImage()));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::loadImage()
    19. {
    20. QString fileName = QFileDialog::getOpenFileName();
    21. image.load(fileName);
    22. scene.addPixmap(image);
    23. ui->widget->loadImage(image);
    24. ui->widget->show();
    25. }
    To copy to clipboard, switch view to plain text mode 

    GraphicsView class:
    Qt Code:
    1. #include "GraphicsView.h"
    2.  
    3. GraphicsView::GraphicsView(QWidget *parent) : QGraphicsView(parent)
    4. {
    5. firstRect = true;
    6. }
    7.  
    8. GraphicsView::~GraphicsView()
    9. {
    10. scene()->clear();
    11. }
    12.  
    13. void GraphicsView::loadImage(QPixmap item)
    14. {
    15. image = item;
    16. }
    17.  
    18. void GraphicsView::mouseReleaseEvent(QMouseEvent *event)
    19. {
    20. if(point1.isNull())
    21. {
    22. point1.setX(event->x());
    23. point1.setY(event->y());
    24. }
    25. else
    26. {
    27. point2.setX(event->x());
    28. point2.setY(event->y());
    29. int width = point2.x() - point1.x();
    30. int height = point2.y() - point1.y();
    31.  
    32. if(firstRect)
    33. {
    34. rect.setRect(point1.x(), point1.y(), width, height);
    35. rect.setPen(QPen(Qt::red));
    36. firstRect = false;
    37. }
    38. else
    39. {
    40. scene()->removeItem(&rect);
    41. rect.setRect(point1.x(), point1.y(), width, height);
    42. }
    43.  
    44. scene()->clear();
    45. scene()->addPixmap(image);
    46. scene()->addItem(&rect);
    47.  
    48. point1.setX(0);
    49. point1.setY(0);
    50. }
    51.  
    52. event->accept();
    53. }
    To copy to clipboard, switch view to plain text mode 
    Platform: Windows 7
    Qt: 4.7.0

    Thanks in advance
    Kuba
    Last edited by K.Sejdak; 13th March 2011 at 00:36.

Similar Threads

  1. Replies: 4
    Last Post: 9th June 2010, 07:46
  2. exited with code -1073741819 error
    By arpspatel in forum Qt Programming
    Replies: 8
    Last Post: 2nd March 2010, 09:47
  3. Replies: 2
    Last Post: 9th November 2009, 09:31
  4. Linker error when i link C code
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2008, 09:48
  5. Error in Q3Canvas Code...
    By Kapil in forum Newbie
    Replies: 10
    Last Post: 27th March 2006, 05:15

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.