[SOLVED] Pointer SLOT Problem "Internal error: pc in read in psymtab, but not in symtab"
-
Hi,
I need help on this one: I want to generate random textures form a Color Palette. The Texture is made visible /editible, due to a canvas made of small QWidgets. First Question is there a better alternative?Now to the Problem I want to discuss. In the mainwinodw I have a
@private: QColor *myColorPalette[10]; //in header file@as well as a slot function:
@private slots:void generate(){ generatePixels(); }@
the generate slot is called by a button click.
The Problem is occuring after the generatePixels() function, but it is from relevance, what happens here:
The ColorPaletteWidget is keeping custom Widgets "ColorPaletteCanvas", these are storing colors, chosen by the user.
I want those color information (QColor) to be stored in the @myColorPalette[]@ QColor array from the Mainwindow
this is how i do it:@ QObjectList thePaletteChildren = myColorPaletteWidget->children();
qDebug()<<"thePaletteChildren size: "<< thePaletteChildren.size(); for(int i = 0; i < thePaletteChildren.size(); i++){ QObject *theChild = thePaletteChildren.at(i); //dynamic cast if not instanceof: theCurrentCanvas = 0 ColorPaletteCanvas *theCurrentCanvas = dynamic_cast<ColorPaletteCanvas*>(theChild); if(theCurrentCanvas != 0){ if(theCurrentCanvas->isActivated()){ myColorPalette[theActiveColors] = theCurrentCanvas->getColor(); // count activated palettes theActiveColors++; } } }//...@
Afterwards, I want to randomly fill a texture with the color informations stored in myColorPalette:
@ //...
int randomPaletteIndex;//for each pixeltile for(int w = 0; w < myDimension; w++){ //my Dimension is the size of the texture, for example 2x2 texture : dimension = 2 for(int h = 0; h < myDimension; h++){
// //generate random number, to choose from palette
randomPaletteIndex = rand() % theActiveColors;PixelCanvasTile *theCurrentTile = myPixelCanvas->getTileAt((w*myDimension)+h); theCurrentTile->setColor(myColorPalette[randomPaletteIndex]); } }
}@
Here Is the getTileAt method :
@PixelCanvasTile* PixelCanvas::getTileAt(int index){
return &myTiles[index];
}@myTiles is an array of PixelCanvasTile
Here the setColor Method:
@void PixelCanvasTile::setColor(QColor *aColor){
if(! this->myColor){
this->myColor = new QColor();
}
this->myColor = aColor;
}@The Problem is the Color is filled in the SLOT Method for ech PixelCanvasTile
but after the SLOT call, in the paintEvent of each PixelCanvasTile myColor is null:
@void PixelCanvasTile::paintEvent(QPaintEvent *){
QPainter thePainter(this);//drawing the rectangle filled with a color QPen thePen(Qt::darkGray); QBrush theDefaultBrush; if( this->myColor){ // ITS NULL ! QColor theColor( this->myColor->rgb()); theDefaultBrush.setColor(theColor); }else{ theDefaultBrush.setColor(Qt::white); }@
When I increase the Dimension of the texture, thus there are more tiles like 16x16
I get an even worse problem in QWidget.h line 481@public Q_SLOTS:
// Widget management functionsvirtual void setVisible(bool visible); inline void setHidden(bool hidden) { setVisible(!hidden); }
#ifndef Q_WS_WINCE
inline void show() { setVisible(true); }@HEAP: Free Heap block 22257e0 modified at 22257f4 after it was freed
(Internal error: pc 0xf in read in psymtab, but not in symtab.)
(Internal error: pc 0xf in read in psymtab, but not in symtab.)Do you know what I am doing wrong?
Kind regards,
Knut
-
It's hard to tell if something is wrong with code without using some debugging.
What i could advise is to use QColor instead of pointer to QColor. QColor is very optimised class (copy on write) and you should not worry about performance. There is possibility that you save pointer to QColor object not created by you and some problems might occure.
-
[quote author="alexisdm" date="1353717167"]@tolszak: QColor is not a copy-on-write class, it stores directly its data. But since it is rather small (14 bytes I think), I agree it doesn't justify using it with raw pointers.[/quote]
You are right. Sorry for that. I don't know why but I was sure that QColor is implemented in such way. Thanks to that mistake I have reviewed implicit sharing docs once again :).
If you use RGB representation you can use QRgb - 1 unsigned int. -
[quote author="tolszak" date="1353749568"]
[quote author="alexisdm" date="1353717167"]@tolszak: QColor is not a copy-on-write class, it stores directly its data. But since it is rather small (14 bytes I think), I agree it doesn't justify using it with raw pointers.[/quote]You are right. Sorry for that. I don't know why but I was sure that QColor is implemented in such way. Thanks to that mistake I have reviewed implicit sharing docs once again :).
If you use RGB representation you can use QRgb - 1 unsigned int.
[/quote]Thank you for your replies so far. So You suggest QColor instead of a Pointer anyway?
-
[quote author="tolszak" date="1353755579"]Right :) I don't know whole of your code but if there are places wher QColor is picked by user and component for color picking is for example QColorDialog there is big possibility of having pointer to color object that does not exist anymore.[/quote]
You were right! I changed it to an object, but still the color is not changing in the drawing paintEvent:
@void PixelCanvasTile::paintEvent(QPaintEvent *){
QPainter thePainter(this);//drawing the rectangle filled with a color QPen thePen(Qt::darkGray); QBrush theDefaultBrush; qDebug()<< "color drawn: "<< this->myColor.rgb(); // stays the same during the hole process QColor theColor( this->myColor.rgb()); theDefaultBrush.setColor(theColor); thePainter.setBrush(theDefaultBrush); thePen.setWidth(1); //number is later the zoomfactor QRect rect(0,0,15,15); thePainter.setPen(thePen); thePainter.drawRect(rect);
}@
I added more code to show how the PixelCanvastiles are produced and stored:
In PixelCanvas.h
@PixelCanvasTile *myTiles;@In the Class file
@
void PixelCanvas::scale(){
myRasterLayout = new QGridLayout(this);
myRasterLayout->setSpacing(0);
for(int w = 0; w < myWidth; w++){
for(int h = 0; h < myHeight; h++){/* *each pixeltile is filed in constructor set as: h = row, w = column * 0 1 2 3 * 4 5 6 7 * 8 9 10 11 * ... */ // create tile increase later myTiles = new PixelCanvasTile(this); myRasterLayout->addWidget(myTiles, h,w,0); myTiles++; } }
}@
// return tile (compare to first post, in the generating method
@PixelCanvasTile* PixelCanvas::getTileAt(int index){
return &myTiles[index];
}@// also used in the generating method of first post here the color is different from the paintingEvent
@void PixelCanvasTile::setColor(QColor *aColor){
qDebug()<< "color set: "<<aColor->rgb();
this->myColor.setRgb(aColor->rgb());
}@ -
Hi I solved it. The Problem was a wron initialized array Pointer:
I devinded it as follows:
@
//.h
PixelCanvasTile *myTiles;
@then in the function loop:
@
for(i < n){
myTiles = new PixelCanvasTiles();
myTiles ++;
@now it is:
@
//.h
PixelCanvasTile **myTiles;// construtor:
myTiles = new PixelCanvasTile*[size];
@in function:
@for(i < n){
myTiles[i] = new PixelCanvasTile();
}@