Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
smiley
Posts: 1,475
Registered: ‎07-14-2008
My Device: Z10

QPainter drawText() func crashes. Is this func supported?

[ Edited ]

Read this old posting

 

http://supportforums.blackberry.com/t5/Cascades-Development/Using-QPainter-on-QImage/m-p/1750877/hig...

 

I'm trying to draw some text on the QPaint image like this

 

    image.drawText(0, 0, "This is my text");

getting this error msg:

 

/base/usr/lib/qt4/lib/libQtGui.so.4.8.3@_ZN13QFontDatabase18addApplicationFontERK7QString+0x1d7

 

and is crashing. 

 

Anyone else have this problem?

 

 

Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: QPainter drawText() func crashes. Is this func supported?

Hi, Could you give us the complete code ? 

a lover of Qt
Please use plain text.
Developer
smiley
Posts: 1,475
Registered: ‎07-14-2008
My Device: Z10

Re: QPainter drawText() func crashes. Is this func supported?

Here is the code.  BTW, draw rectangle works just not drawtext.

 

    // Set image name
    reader.setFileName(fileName);

 

    QImage image = reader.read();

    // Paint an text on the image
    QPainter img(&image);

    img.setPen(Qt::red);

    QString str("This is a text");

 

    // crashes here
    img.drawText(0,0, str);

Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha

Re: QPainter drawText() func crashes. Is this func supported?

Do like this :

QPixmap pix(100,100);
pix.fill(Qt::red);
QPainter paint(&pix);
pix.drawText(0,0,"hello");

pix.toImage();

a lover of Qt
Please use plain text.
Developer
smiley
Posts: 1,475
Registered: ‎07-14-2008
My Device: Z10

Re: QPainter drawText() func crashes. Is this func supported?


dridk wrote:
Do like this :

QPixmap pix(100,100);
pix.fill(Qt::red);
QPainter paint(&pix);
pix.drawText(0,0,"hello");

pix.toImage();


thanks for the code by pix class does not have drawText().

 

this is what i've done.  No crashes and no text printed.

 

    // Set image name from the given file name.
    reader.setFileName(fileName);
    QImage image = reader.read();

    // Paint an text on the image
    QPainter merger(&image);

    QPixmap pix(100,100);
    pix.fill(Qt::red);
    QPainter paint(&pix);

 

    // changed pix to paint.  does this work?
    paint.drawText(0,0,"hello");

 

    // write the pixmap to the bitmap.  doesn't draw the pixmap
    merger.drawPixmap(0,0,  pix);

 

Please use plain text.
Developer
smiley
Posts: 1,475
Registered: ‎07-14-2008
My Device: Z10

Re: QPainter drawText() func crashes. Is this func supported?


dridk wrote:
Do like this :

QPixmap pix(100,100);
pix.fill(Qt::red);
QPainter paint(&pix);
pix.drawText(0,0,"hello");

pix.toImage();


Do you have an example that works in Cascade C++?  thanks

 

Please use plain text.