Results 1 to 20 of 27

Thread: no compile error, error on run

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default no compile error, error on run

    I can compile my project with no error, but a windows error (send report, end task) suddenly appears when the program executes this function.

    By the way, I am trying to resize a loaded Image to the scene's size keeping the image's aspect ratio. any other suggestions would be nice.

    Qt Code:
    1. void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this,
    4. tr("Open Image"), QDir::currentPath());
    5. if (!fileName.isEmpty())
    6. {
    7. QImage tempImage(fileName);
    8. if (tempImage.isNull())
    9. {
    10. QMessageBox::information(this, tr("Load Warning"),
    11. tr("Cannot load %1.").arg(fileName));
    12. return;
    13. }
    14. QImage image = tempImage.convertToFormat(QImage::Format_ARGB32);
    15. QGraphicsScene* viewScene = graphicsView->scene();
    16. QPixmap pixmap = QPixmap::fromImage(image);
    17.  
    18. scene->addPixmap(pixmap.scaled(QSize((int)viewScene->width(), (int)viewScene->height()), Qt::KeepAspectRatio, Qt::SmoothTransformation));
    19.  
    20. qDebug() << "Width = " << viewScene->width();
    21. qDebug() << "Height = " << viewScene->height();
    22.  
    23. graphicsView->setScene(scene);
    24. graphicsView->show();
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by sincnarf; 18th September 2007 at 07:43. Reason: insufficient info
    Image Analysis Development Framework Using Qt (IADFUQ)

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    I don't think this works:
    Qt Code:
    To copy to clipboard, switch view to plain text mode 
    It is unlikely to be able to add items to a scene without a view. It's view is NULL and I am sure it tries to use it somewhere.

    Try setting the scene to the view immediately after creating scene.

  3. The following user says thank you to marcel for this useful post:

    sincnarf (18th September 2007)

  4. #3
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    how do I determine if the passed graphicsView and its graphicsScene is null?

    i'm looking for something like a view.isNull() method and view->scene().isNull method
    Last edited by sincnarf; 18th September 2007 at 08:20. Reason: double post
    Image Analysis Development Framework Using Qt (IADFUQ)

  5. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    But I already told you. The solution is to setScene right after you create it. Nothing more.
    Anyway, if you want to test the view of a scene use QGraphicsScene::views(). It returns a QList of QGraphicsView. In your case it should be empty.

  6. The following user says thank you to marcel for this useful post:

    sincnarf (19th September 2007)

  7. #5
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    Qt Code:
    1. void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
    2. {
    3.  
    4. if (graphicsView == 0)
    5. {
    6. QMessageBox::warning(this, tr("Load Error"), tr("Graphics View is NULL"));
    7. return;
    8. }
    9. QGraphicsScene *scene = graphicsView->scene();
    10. QGraphicsView *view = graphicsView;
    11. view->setScene(scene);
    12. if (scene->views().size() == 0)
    13. {
    14. QMessageBox::warning(this, tr("Load Error"), tr("GraphicsView's GraphicsScene is NULL"));
    15. return;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    and this
    Qt Code:
    1. void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
    2. {
    3.  
    4. if (graphicsView == 0)
    5. {
    6. QMessageBox::warning(this, tr("Load Error"), tr("Graphics View is NULL"));
    7. return;
    8. }
    9. if ( graphicsView->scene()->views().size() == 0)
    10. {
    11. QMessageBox::warning(this, tr("Load Error"), tr("GraphicsView's GraphicsScene is NULL"));
    12. return;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    causes the same windows error
    Last edited by sincnarf; 18th September 2007 at 09:10. Reason: double post
    Image Analysis Development Framework Using Qt (IADFUQ)

  8. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    Qt Code:
    1. void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
    2. {
    3. QString fileName = QFileDialog::getOpenFileName(this,
    4. tr("Open Image"), QDir::currentPath());
    5. if (!fileName.isEmpty())
    6. {
    7. QImage tempImage(fileName);
    8. if (tempImage.isNull())
    9. {
    10. QMessageBox::information(this, tr("Load Warning"),
    11. tr("Cannot load %1.").arg(fileName));
    12. return;
    13. }
    14. QImage image = tempImage.convertToFormat(QImage::Format_ARGB32);
    15. QGraphicsScene* viewScene = graphicsView->scene();
    16. float w = viewScene->width();
    17. float h = viewScene->height();
    18.  
    19. graphicsView->setScene(scene);
    20. delete viewScene;
    21.  
    22. QPixmap pixmap = QPixmap::fromImage(image);
    23. scene->addPixmap(pixmap.scaled(QSize((int)w, (int)h, Qt::KeepAspectRatio, Qt::SmoothTransformation));
    24.  
    25. qDebug() << "Width = " << w;
    26. qDebug() << "Height = " << h;
    27.  
    28. graphicsView->show();
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to marcel for this useful post:

    sincnarf (19th September 2007)

  10. #7
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    didn't work. . . same windows error problem
    Image Analysis Development Framework Using Qt (IADFUQ)

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

    Default Re: no compile error, error on run

    How about... using a debugger?

  12. The following user says thank you to wysota for this useful post:

    sincnarf (19th September 2007)

  13. #9
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    what's a debugger? I'm using eclipse CDT plugin and I don't know how to debug this
    Image Analysis Development Framework Using Qt (IADFUQ)

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

    Default Re: no compile error, error on run

    Debugger is a tool that let's you inspect the developped application while it's running. Among other things, it would tell you where exactly your application crashes. If you're using MinGW as a compiler using GDB for debugging is the best option.

  15. The following user says thank you to wysota for this useful post:

    sincnarf (19th September 2007)

  16. #11
    Join Date
    Apr 2007
    Posts
    117
    Thanks
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: no compile error, error on run

    GDB says something like this... I can't understand...

    Program received signal SIGSEGV, Segmentation fault.
    0x00b2b2be in ZNK14QGraphicsScene9sceneRectEv ()
    (gdb) backtrace
    #0 0x00b2b2be in ZNK14QGraphicsScene9sceneRectEv ()
    #1 0x00407453 in ?? ()
    #2 0x0022b00c in ?? ()
    #3 0x00000000 in ?? ()
    Image Analysis Development Framework Using Qt (IADFUQ)

Similar Threads

  1. Use VC2005 to compile Qt program (4.3.0)
    By firegun9 in forum Qt Programming
    Replies: 3
    Last Post: 8th June 2007, 16:04
  2. Qt-4.2.2 qmake won't compile under visual studio 2005 on vista
    By moowy in forum Installation and Deployment
    Replies: 7
    Last Post: 13th January 2007, 21:06
  3. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  4. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  5. Can't Compile Tutorial 7
    By Reenen in forum Newbie
    Replies: 10
    Last Post: 9th February 2006, 14:06

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
  •  
Qt is a trademark of The Qt Company.