Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, September 2007
problem with QPainterPath.united()


Message 1 in thread

Hi all,

  can anyone explain why following code freezes? All it does is
create some painter paths and unite them together using
QPainterPath.united()

- only when united() is called from mouseReleaseEvent() handler,
  the error occurs, when it is called from somewhere else, eg. from
  main() it does not
- with QPainterPath.subtracted() and different input happens
  the same

Am i doing something wrong? Thanks in advance for any suggestions.

I attach the source code and the simplest input that causes the error.

Tomas
#include <QApplication>
#include <QMainWindow>

#include "qpp_w.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QMainWindow mw;
    mw.setCentralWidget(new MyWidget(&mw));
    mw.show();
    app.exec();
}
#include <QApplication>
#include <QApplication>
#include <QWidget>
#include <QPainterPath>
#include <cstdio>

class MyWidget : public QWidget {
    Q_OBJECT
public:
    MyWidget(QWidget *parent) : QWidget(parent) {}
protected:
    void mouseReleaseEvent(QMouseEvent *event)
    {
        QPainterPath path;
        QPainterPath newPath;
        FILE *f = fopen("path", "r");
        char line[256];
        while (fgets(line, 255, f)) {
            int x, y;
            switch (line[0]) {
                case 'm':
                    sscanf(line, "m %d, %d\n", &x, &y);
                    newPath.moveTo(x, y);
                    break;
                case 'l':
                    sscanf(line, "l %d, %d\n", &x, &y);
                    newPath.lineTo(x, y);
                    break;
                case 'u':
                    path = path.united(newPath);
                    newPath = QPainterPath();
                    break;
                default:
                    printf("unknown command\n");
                    break;
            }
            printf(line);
        }
        fclose(f);
        printf("end of input\n");
        QApplication::exit(0);
    }
};

m  1,20
m  1,20
l 30,30
l 10,20
l 10,30
u
m  1,10
l  1,20
l 30,30
u