PDA

View Full Version : Getting X-errors during runtime while drawing rectangles on qwidget



Anitha
13th January 2006, 09:40
Hello,
My application is an MDI and on one of the child windows, i need to draw 1500 rectangles to depict the overall status of the system. The drawing is been done on a jpeg image. The drawing is done fine, but as i go on opening and closing the child windows one by one i get the following X-errors while the app is running :

X Error: BadGC (invalid GC parameter) 13
Major opcode: 66
Minor opcode: 0
Resource id: 0x2e0043c
X Error: BadGC (invalid GC parameter) 13
Major opcode: 66
Minor opcode: 0
Resource id: 0x2e0043c
X Error: BadGC (invalid GC parameter) 13
Major opcode: 66
Minor opcode: 0
Resource id: 0x2e0043c..........

My paintevent code is as below :

void CascadeOverview::paintEvent(QPaintEvent *)
{
static int X1,Y1,X2,Y2;
Y1 = 5;
Y2 = 10;
QImage cascadeBG("./images/cascadebackground.png"); // jpeg image
QPixmap bufferCascadeBG(cascadeBG);

if (paintActualArea->isActive())
paintActualArea->end();

if (paintBufferArea->isActive())
paintBufferArea->end();

paintActualArea->begin(pixmapBackground);
paintBufferArea->begin(&bufferCascadeBG);

paintActualArea->setBrush(green);
paintBufferArea->setBrush(green);

for( int i=0;i<1500;i++)
{

paintActualArea->drawRect(X1,Y1,5,10);
paintBufferArea->drawRect(X1,Y1,5,10);

X1= X1+25;
X2 = X2+25;
if(X1>1250)
{
X1=0;
Y1 = Y1+10;
Y2 = Y2+10;
}
if(X2>1250)
{
X2=0;
Y1 = Y1+10;
Y2 = Y2+10;
}

}
bitBlt (pixmapBackground, 0, 0, &bufferCascadeBG);

paintBufferArea->end();
paintActualArea->end();


}


should i detach the image once painter is ended or is there any specific means to release the graphic objects in qt(like GDI in windows)

Thanks for help in advance,
Anitha.

jacek
13th January 2006, 16:19
It looks like that Y1 variable goes up to 15000.

Qt docs say:
Warning: Note that QPainter does not attempt to work around coordinate limitations in the underlying window system. Some platforms may behave incorrectly with coordinates as small as +/-4000. Maybe that's the problem?

Anitha
17th January 2006, 06:12
I have tried drawing less number of rectangles, but i still get the errors :( The errors occur very randomly, so should i follow any work around to free the memory or something like that. Please do reply.

Anitha

vitaly
17th January 2006, 08:49
May be you should try to create QPainter's in the paintEvent() like this:




void CascadeOverview:paintEvent(QPaintEvent *)
{
static int X1,Y1,X2,Y2;
Y1 = 5;
Y2 = 10;

QImage cascadeBG("./images/cascadebackground.png");
QPixmap bufferCascadeBG(cascadeBG);

QPainter paintActualArea(pixmapBackground);
QPainter paintBufferArea(&bufferCascadeBG);

paintActualArea.setBrush(green);
paintBufferArea.setBrush(green);

for( int i=0;i<1500;i++)
{
paintActualArea.drawRect(X1,Y1,5,10);
paintBufferArea.drawRect(X1,Y1,5,10);

X1= X1+25;
X2 = X2+25;
if(X1>1250)
{
X1=0;
Y1 = Y1+10;
Y2 = Y2+10;
}

if(X2>1250)
{
X2=0;
Y1 = Y1+10;
Y2 = Y2+10;
}
}

bitBlt(pixmapBackground, 0, 0, &bufferCascadeBG);
}

high_flyer
17th January 2006, 18:46
I have tried drawing less number of rectangles,
What jacek pointed out is still true.
The problem is not the number of rectangles, but the value of Y1!