Hi, 

the small appended program crashes when you do the following:

- compile it with VS 2008, SP1 on WINDOWS XP, SP3 using Qt-4.6.0-rc1
- start it
- press the shortcut key "A" to activate the slot-function
"moveToBackground" 
- close it

it crashes in the line "delete d->topLevelItems.first();" while trying to
use an already deleted item.

Best, Michael.
#include <QtGui>

static QGraphicsScene *myScene;
static QList<QGraphicsRectItem *> *myList;

class GraphicsView: public QGraphicsView
{
        Q_OBJECT

public:
        GraphicsView(QGraphicsScene *scene, QWidget *parent): 
                QGraphicsView(scene,parent) {}

public slots:
        void moveToBackground();
};

void GraphicsView::moveToBackground() 
{
        QGraphicsItem *item=myList->at(2);
        myScene->removeItem(item);
        item->setZValue(0);
        myScene->addItem(item);
}

#include "main.moc"

int main(int argc, char **argv)
{
        QApplication app(argc, argv);

        QGraphicsScene scene;
        myScene=&scene;
        scene.setSceneRect(0, 0, 800, 480);
        scene.setItemIndexMethod(QGraphicsScene::NoIndex);

        QList<QGraphicsRectItem *> list;
        myList=&list;
        list.append(new QGraphicsRectItem(10,15,20,25));
        list.append(new QGraphicsRectItem(20,17,20,25));
        list.append(new QGraphicsRectItem(14,24,20,25));

        QColor colors[3]={
                QColor(Qt::red),        //z==1
                QColor(Qt::green),      //z==2
                QColor(Qt::blue)        //z==3
        };

        for (int i=0; i < 3; ++i) {
                list[i]->setFlag(QGraphicsItem::ItemIsMovable);
                list[i]->setFlag(QGraphicsItem::ItemIsSelectable);
                list[i]->setZValue(i+1);
                list[i]->setPen(QPen(colors[i]));
                scene.addItem(list[i]);
        }
        scene.setBackgroundBrush(Qt::white);
        GraphicsView *view = new GraphicsView(&scene,NULL);
        QAction *pAct=new QAction(view);
        new 
QShortcut(QString::fromLatin1("A"),view,SLOT(moveToBackground()),SLOT(moveToBackground()));
        
QObject::connect(pAct,SIGNAL(triggered()),view,SLOT(moveToBackground()));

        view->show();
        return app.exec();
}
_______________________________________________
Qt4-preview-feedback mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt4-preview-feedback

Reply via email to