c++ - 缩小 QGraphicsView 会崩溃

标签 c++ qt crash qgraphicsview qgraphicsscene

我有一个自定义的 QGraphicsScene 类,我想在进行一些鼠标移动时对其进行缩放。 只要因子 >= 1.0,缩放就可以正常工作。但是当因子小于 1 时,它会因为(我相信循环)而崩溃。
这是处理缩放和解释循环的代码:

 void NodeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    {
// Start of function
        QPointF newCoord=event->scenePos();
        if (zooming) // Zooming only set to true when using right mouse button with Alt-key pressed
        {
            mainView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);

            // Scale the view / do the zoom

            if(newCoord.x()>lastMouseCoord.x())
            {
                // Zoom in
                mainView->scale(1.03f, 1.03f);

            }

            if(newCoord.x()<lastMouseCoord.x())
            {
                // Zoom out
                mainView->scale(0.97f, 0.97f); --> Goes back to start of function and then zooming out again and then start of function... etc... until crashing
            }

            lastMouseCoord=newCoord;

        }

    }

知道为什么缩小会立即启动功能吗?谢谢

最佳答案

我必须在zoomout函数之前实现一个全局变量的初始化,如果这个变量是在进入mouseMoveEvent时初始化的,那么我就直接退出这个函数。

关于c++ - 缩小 QGraphicsView 会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33230624/

相关文章:

c++ - 在 C++ 中赋予回调函数访问类数据成员的权限

c++ - WINDOWPLACEMENT 的 showCmd...总是 1?

c++ - Qt QString 获取大量内存

android - 当我尝试在选项卡之间切换时应用程序崩溃

Node.js(&MongoDB)服务器崩溃,数据库操作中途?

forms - Xamarin Forms 应用程序崩溃没有日志

c++ - 通过指针更新多个 STL 容器中的对象

c++ - 什么是聚合初始化

带有调试器的 QT

c++ - QObject :connect No such slot issue