PDA

View Full Version : QImage::bits() overloaded function



s410i
9th December 2009, 12:25
Hello!

In QImage class we have function bits() witch is overloaded:


uchar * bits ()
const uchar * bits () const


My problem is that when I want to call uchar * bits () function, just like that:


uchar *bitsImage = image.bits();

I'm getting an error:
error: invalid conversion from 'const uchar*' to 'uchar*'

So I would like to ask how I can call the uchar * bits () function?

Best regards
s410i

yogeshgokul
9th December 2009, 13:04
Hello!

In QImage class we have function bits() witch is overloaded:


uchar * bits ()
const uchar * bits () const


My problem is that when I want to call uchar * bits () function, just like that:


uchar *bitsImage = image.bits();

I'm getting an error:
error: invalid conversion from 'const uchar*' to 'uchar*'

So I would like to ask how I can call the uchar * bits () function?

Best regards
s410i
Although its strange.
Anyway you can use casting operators. e.g.

uchar *bitsImage = const_cast <uchar*> image.bits();

wysota
9th December 2009, 18:06
So I would like to ask how I can call the uchar * bits () function

This works fine for me:

#include <QImage>

int main(){
QImage img;
uchar *bits = img.bits();
return 0;
}

Your "image" variable is probably const. You can't call non-const methods on a const object.

s410i
9th December 2009, 20:50
Thank you very much :)

const QImage was the problem.

Best regards
s410i