[Qt-interest] Problem with mapToScene

Chris thatchman at gmail.com
Wed Dec 31 17:41:28 CET 2008


It's hard to say without seeing the rest of the code, the first thing I
would check is that your GPPECanvasView class has a valid scene set with the
QGraphicsView::setScene() function, and that QGraphicsView::scene() returns
a valid pointer when you call it in the same context you're calling
mapToScene().

~Chris

On Tue, Dec 30, 2008 at 7:19 AM, kisna raj <kisna at walla.com> wrote:

> Hi,
>
> I have a problem using QGrpahicsView's mapToScene.
>
>
>
> The following is the code snippet that i use
>
>
>
> void GPPECanvasView:: mousePressEvent(QMouseEvent* e)
>
> {
>
>         QGraphicsView::mousePressEvent(e);
>
>         QPoint point = e->pos();
>
>         startX = point.x();
>
>         startY = point.y();
>
> }
>
>
>
> void GPPECanvasView::mouseReleaseEvent ( QMouseEvent * e )
>
> {
>
>         QGraphicsView::mouseReleaseEvent(e);
>
>         QPoint point = e->pos();
>
>         endX = point.x();
>
>         endY = point.y();
>
>
>
>         if( endY > startY )
>
>         {
>
>                 if( UIUtil::getMagnification() < 65535 )
>
>                 {
>
>                         UIUtil::setMagnification(
> UIUtil::getMagnification() * 2 );
>
>                 }
>
>         }
>
>         else
>
>         {
>
>                 if( UIUtil::getMagnification() > 1 )
>
>                 {
>
>                         UIUtil::setMagnification(
> UIUtil::getMagnification() / 2 );
>
>                 }
>
>
>
>         }
>
>         QRect* rrect = new QRect( QPoint(startX,startY), QPoint(endX,endY)
> );
>
>         QPoint center = rrect->center();
>
>
>
>         QPointF point1 =  mapToScene(center);
>
>
>
>         UIUtil::getCanvasView()->centerOn(point1);
>
> }
>
>
>
>
>
> Note: GPPECanvasview inherits QGraphicsView.
>
>
>
> Also the trace shows the following.
>
>
>
> Program received signal SIGSEGV, Segmentation fault.
>
> [Switching to Thread 47990737800192 (LWP 18051)]
>
> 0x00000000009593a6 in QGraphicsViewPrivate::horizontalScroll ()
>
> (gdb) bt
>
> #0  0x00000000009593a6 in QGraphicsViewPrivate::horizontalScroll ()
>
> #1  0x00000000009597da in QGraphicsView::mapToScene ()
>
> #2  0x00000000004c3cca in GPPECanvasView::mouseReleaseEvent
> (this=0x1208780, e=0x7ffff5dcd740) at gppecanvasview.cpp:255
>
> #3  0x00000000005a0f55 in QWidget::event ()
>
> #4  0x000000000082a966 in QFrame::event ()
>
> #5  0x000000000089e4da in QAbstractScrollArea::viewportEvent ()
>
> #6  0x000000000095c49b in QGraphicsView::viewportEvent ()
>
> #7  0x000000000089f658 in QAbstractScrollAreaFilter::eventFilter ()
>
> #8  0x0000000000b3a75e in
> QCoreApplicationPrivate::sendThroughObjectEventFilters ()
>
> #9  0x000000000055ca40 in QApplicationPrivate::notify_helper ()
>
> #10 0x0000000000565d19 in QApplication::notify ()
>
> #11 0x0000000000b3aca9 in QCoreApplication::notifyInternal ()
>
> #12 0x0000000000560bbf in QApplicationPrivate::sendMouseEvent ()
>
> #13 0x00000000005afbf1 in QETWidget::translateMouseEvent ()
>
> #14 0x00000000005aeaa6 in QApplication::x11ProcessEvent ()
>
> #15 0x00000000005cd135 in x11EventSourceDispatch ()
>
> #16 0x00002ba5b60b8fca in g_main_context_dispatch () from
> /opt/gnome/lib64/libglib-2.0.so.0
>
> #17 0x00002ba5b60bc055 in __gxx_personality_v0 () from
> /opt/gnome/lib64/libglib-2.0.so.0
>
> #18 0x00002ba5b60bc57e in g_main_context_iteration () from
> /opt/gnome/lib64/libglib-2.0.so.0
>
> #19 0x0000000000b5c2ee in QEventDispatcherGlib::processEvents ()
>
> #20 0x00000000005ccf4f in QGuiEventDispatcherGlib::processEvents ()
>
> #21 0x0000000000b39ee5 in QEventLoop::processEvents ()
>
> #22 0x0000000000b3a12a in QEventLoop::exec ()
>
> #23 0x0000000000b3c071 in QCoreApplication::exec ()
>
> #24 0x000000000040ec57 in ControllerFacade::init (this=0x11d2850, argc=1,
> argv=0x7ffff5dce808) at ControllerFacade.cpp:138
>
> #25 0x00000000004131af in main (argc=1, argv=0x7ffff5dce808) at main.cpp:7
>
>
>
>
>
>
>
> The mapToScene crashes anywhere in the program.
>
> Please help me to fix the issue.
>
> Regards,
>
> Kisna
>
>
>
> ------------------------------
> Walla! Mail - Get your free unlimited mail today <http://www.walla.com>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081231/c5bdb6fb/attachment.html 


More information about the Qt-interest-old mailing list