Page 1 of 2 12 LastLast
Results 1 to 20 of 27

Thread: no compile error, error on run

  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,017 Times in 4,793 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,017 Times in 4,793 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)

  17. #12
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: no compile error, error on run

    Try compiling the application in debug mode:
    make clean
    qmake -config debug
    make
    J-P Nurmi

  18. The following user says thank you to jpn for this useful post:

    sincnarf (19th September 2007)

  19. #13
    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

    Quote Originally Posted by jpn View Post
    Try compiling the application in debug mode:
    Sorry but what;s next?

    anyway here's additional debugging info.
    Program received signal SIGSEGV, Segmentation fault.
    0x00fa8bc2 in QGraphicsScene::d_func (this=0x0) at graphicsview//qgraphicsscene.h:237
    237 Q_DECLARE_PRIVATE(QGraphicsScene)
    The line Q_DECLARE_PRIVATE(QGraphicsScene) obviously has an error using my function. but what does this mean? Anyway, I am out of ideas of how I can load an Image to a QGraphicsView and automatically scale that Image based on the GraphicsView's size.. keeping aspectratio. Maybe there are other ways to do this

    All the modifications to my function all have the same error.
    Last edited by sincnarf; 19th September 2007 at 10:17. Reason: avoid double post
    Image Analysis Development Framework Using Qt (IADFUQ)

  20. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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

    Show us the backtrace after compiling in debug mode. There is nothing obvious here

    By the way - do you need to use graphics view or do you just want to display an image? If the latter then use QLabel instead. If you insist on using the graphics view then create a scene with size equal to the image size, add the image to the scene and tell the view to scale the scene using fitInView().

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

    sincnarf (19th September 2007)

  22. #15
    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

    Quote Originally Posted by wysota View Post
    Show us the backtrace after compiling in debug mode. There is nothing obvious here
    here's the backtrace

    #0 0x00fa8bc2 in QGraphicsScene::d_func (this=0x0) at graphicsview//qgraphicsscene.h:237
    #1 0x00e71695 in QGraphicsScene::sceneRect (this=0x0) at graphicsview/qgraphicsscene.cpp:1048
    #2 0x0043369a in QGraphicsScene::width (this=0x0) at ../../Qt/4.3.1/include/QtGui/../../src/gui/graphicsview/qgraphicsscene.h:118
    #3 0x0040ac7b in MainWindow::loadGraphicsViewParameter (this=0x22fbe0, graphicsView=0x4232d98) at mainwindow.cpp:828
    #4 0x0040b17d in MainWindow::loadGraphicsViewParameter1 (this=0x22fbe0) at mainwindow.cpp:880
    #5 0x00412d5f in MainWindow::qt_metacall (this=0x22fbe0, _c=InvokeMetaMethod, _id=35, _a=0x22b904) at debug/moc_mainwindow.cpp:187
    #6 0x10119529 in QMetaObject::activate (sender=0x4250a68, from_signal_index=29, to_signal_index=30, argv=0x22b904) at kernel/qobject.cpp:3080
    #7 0x10119950 in QMetaObject::activate (sender=0x4250a68, m=0x1049910, from_local_signal_index=2, to_local_signal_index=3, argv=0x22b904) at kernel/qobject.cpp:3159
    #8 0x00eadd7f in QAbstractButton::clicked (this=0x4250a68, _t1=false) at tmp/moc/debug_shared/moc_qabstractbutton.cpp:180
    #9 0x00c0105e in QAbstractButtonPrivate::emitClicked (this=0x4250708) at widgets/qabstractbutton.cpp:532
    #10 0x00c00f79 in QAbstractButtonPrivate::click (this=0x4250708) at widgets/qabstractbutton.cpp:525
    #11 0x00c0296c in QAbstractButton::mouseReleaseEvent (this=0x4250a68, e=0x22c1bc) at widgets/qabstractbutton.cpp:1102
    #12 0x008c789f in QWidget::event (this=<incomplete type>, event=0x22c1bc) at kernel/qwidget.cpp:6080
    #13 0x00c0281e in QAbstractButton::event (this=0x4250a68, e=0x22c1bc) at widgets/qabstractbutton.cpp:1064
    #14 0x00cc278c in QPushButton::event (this=0x4250a68, e=0x22c1bc) at widgets/qpushbutton.cpp:667
    #15 0x0087654d in QApplicationPrivate::notify_helper (this=0x3d4bb8, receiver=0x4250a68, e=0x22c1bc) at kernel/qapplication.cpp:3558
    #16 0x00874e1a in QApplication::notify (this=0x22fdf0, receiver=0x4250a68, e=0x22c1bc) at kernel/qapplication.cpp:3257
    #17 0x100ffc84 in QCoreApplication::notifyInternal (this=0x22fdf0, receiver=0x4250a68, event=0x22c1bc) at kernel/qcoreapplication.cpp:532
    #18 0x00ef6504 in QCoreApplication::sendSpontaneousEvent (receiver=0x4250a68, event=0x22c1bc) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:205
    #19 0x008dad26 in QETWidget::translateMouseEvent (this=0x4250a68, msg=@0x22d9bc) at kernel/qapplication_win.cpp:2774
    #20 0x008d56b1 in QtWndProc (hwnd=0x504be, message=514, wParam=0, lParam=786451) at kernel/qapplication_win.cpp:1407
    #21 0x77d48709 in USER32!GetDC () from C:\WINDOWS\system32\user32.dll
    Quote Originally Posted by wysota View Post
    By the way - do you need to use graphics view or do you just want to display an image? If the latter then use QLabel instead. If you insist on using the graphics view then create a scene with size equal to the image size, add the image to the scene and tell the view to scale the scene using fitInView().
    Yes, I really need QGraphicsView. Testing your recommendation...
    Image Analysis Development Framework Using Qt (IADFUQ)

  23. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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

    Look here:
    #3 0x0040ac7b in MainWindow::loadGraphicsViewParameter (this=0x22fbe0, graphicsView=0x4232d98) at mainwindow.cpp:828
    loadGraphicsViewParameter() is called and inside it:
    #2 0x0043369a in QGraphicsScene::width (this=0x0) at ../../Qt/4.3.1/include/QtGui/../../src/gui/graphicsview/qgraphicsscene.h:118
    You fetch the width of the scene, but look at the value of "this" - it's null. It means that the scene is invalid.

    After looking at your code you may notice that you call width() on the "viewScene" which is obviously null.

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

    sincnarf (5th October 2007)

  25. #17
    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

    At last the windows error is gone BUT I still can't get the scene/image to fit in the view using this

    Qt Code:
    1. void MainWindow::loadGraphicsViewParameter(QGraphicsView *graphicsView)
    2. {
    3.  
    4. QString fileName = QFileDialog::getOpenFileName(this,
    5. tr("Open Image"), QDir::currentPath());
    6. if (!fileName.isEmpty())
    7. {
    8. QImage tempImage(fileName);
    9. if (tempImage.isNull())
    10. {
    11. QMessageBox::information(this, tr("Load Warning"),
    12. tr("Cannot load %1.").arg(fileName));
    13. return;
    14. }
    15. QImage image = tempImage.convertToFormat(QImage::Format_RGB32);
    16. QGraphicsScene *scene = new QGraphicsScene(QRectF(0, 0, image.width(), image.height()), 0);
    17. scene->addPixmap(QPixmap::fromImage(image));
    18. int width = graphicsView->geometry().width();
    19. int height = graphicsView->geometry().height();
    20. // qDebug() << "W = " << width;
    21. // qDebug() << "H = " << height;
    22. graphicsView->setScene(scene);
    23. graphicsView->fitInView(QRectF(0, 0, width,height), Qt::KeepAspectRatio);
    24. graphicsView->show();
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    Image Analysis Development Framework Using Qt (IADFUQ)

  26. #18
    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

    use scene->setSceneRect(0, 0, image->width(), image->height());

  27. #19
    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

    no effect, i put your recommendation before the setScene, after setScene, both before and after setScene, nothing .... the image does not fit to the graphics view
    Image Analysis Development Framework Using Qt (IADFUQ)

  28. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 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

    In what way does it "not fit"? Is it bigger or smaller than the view?

    BTW. Are you aware that the view will only have its size determined after it is shown for the first time? Asking for its size before it is shown for the first time will return bogus data... And it seems to be what is happening here.

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.