Pasted as C++ by xavier_g [ Create new paste | Remove this paste ]
Description: Dashed Ellipse Demo Bug
URL: http://rafb.net/p/UIYwOl22.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
mkdir debd
cd debd
put this code under debd.cpp
qmake-qt4 -project
qmake-qt4
make
# should work
./debd -solid
# shouldn't work
./debd
 
### code ###
#include <QtGui>
 
/**
	Dashed Ellipse Bug Demo - xavier.guerrin@gmail.com
	This program draws an ellipse with a solid or dashed line style to show
	a bug encountered under Fedora 9 : 
	Run ./debd -solid : it should work
	Run ./debd : it should take 100 % CPU and should not be able to render the ellipse
*/
int main(int argc, char **argv) {
	QApplication app(argc, argv);
 
	// Choose a dashed or solid QPen, depending on arguments
	Qt::PenStyle linestyle = app.arguments().contains("-solid") ? Qt::SolidLine : Qt::DashLine;
	QPen pen(QBrush(Qt::NoBrush), 10.0, linestyle, Qt::SquareCap, Qt::BevelJoin);
	pen.setColor(Qt::black);
 
	// Draws an ellipse onto a QPicture
	QPicture picture;
	QPainter qp(&picture);
	qp.setPen(pen);
	qp.drawEllipse(50, 50, 540, 380);
	qp.end();
 
	// Creates a simple QPixmap
	QPixmap pixmap(640, 480);
	pixmap.fill();
 
	// Renders the QPicture onto the QPixmap
	QPainter painter(&pixmap);
	qDebug() << "beginning rendering";
	picture.play(&painter);
	qDebug() << "finished rendering";
 
	// Displays the resulting QPixmap
	QLabel display;
	display.setPixmap(pixmap);
	display.show();
 
	return(app.exec());
}