PDA

View Full Version : Qstring convert to...



xxxollixxx
28th November 2013, 12:27
Hi Guys,

I'm working with Qt since 2 weeks now and it's really interesting to me. My first task is to read out a image(raw-file) and to display it. So it take a while, but now I made some progress. I included the raw-file as a resource to my programm, made a QImage with an 8bit grayscale colourmap and read the file data to a string. Oh I forgot, the raw-file is very simple and contains only pixeldata, the size is about 131072 signs and this value fits to the resolution of 512x256 pixels. The pixels are stored as ascii-signs within the file, I was able to read the pixel value(0-255) with an hex-editor and guess it is ascii.
So the next step is to read out the file-data to a QString(or similar) and convert it to int or const char(value 0-255). Therefore I wrote this code:

QFile file(":/new/1.raw");
if(file.open(QIODevice::ReadOnly|QIODevice::Text)) {qDebug("File opened");}
else{qDebug("File not opened");}
QTextstream out(&file);
QString str= out.readAll();

Now I'm really not sure about the datatype of str and how to get my pixel value's or even create an output for the ascii data on a label. Hope someone can give me a hint on this?

Best reagards,

Olli

Santosh Reddy
28th November 2013, 13:17
Here is an example


QString inputData = "FF00F100B200FF00";
QList<int> outputData;

for(int i = 0; i < inputData.size(); i+=2)
outputData << inputData.mid(i, 2).toUInt(0, 16);

qDebug() << outputData; // will print (255, 0, 241, 0, 178, 0, 255, 0)

xxxollixxx
28th November 2013, 13:40
Thanks alot for the reply! I tested your code and it works, like you say. There is only one problem left, I dont got the pixel value in hex "FF" for "255". I got f.ex. "÷" that means value "247". Is there is a way to change the input format? But anyway it's a good hint for me!

Best regards,

Olli

Santosh Reddy
28th November 2013, 13:56
In that case read the file in binary mode (instead of text mode) and read into QByteArray

xxxollixxx
28th November 2013, 13:58
thx I'll take a look on it!