PDA

View Full Version : QString resize() or count()



nagabathula
27th December 2010, 06:54
hello friends, i have a small problem. I am retrieving some temperature data from a embbeded system on rs232 terminal which i am saving into a db.. I have done everything but i am having problem with aligning the data from a bulk db to make it into under stable form. How can i push exactly 2944 chars from a string to db one row at a time, cause here one master frame of data is 2944 chars since i am using QString mid to remove the frame id from the retrieved data from the db, when the data is continued from the 1st row to 2nd the count is missed and the aligning is not proper.. I know this problem will be solved if in case i save 2944 chars each row in the db.. should i use datstr.resize(2944); or datstr.count(2944) so that only so many chars are saved into it before i push the data into the data base..
i am appending continuous data into QString stfram; before i save it to the data base. how can i restrict the data to 2944 chars in each row in the db while saving into the db sir.



QString sq("INSERT INTO Bulkdb values(%1, %2)");
sq = sq.arg(rcount)
.arg("'" + stfram + "'");
m_query.exec(sq);
rcount++;
stfram.clear();

thank you

franz
27th December 2010, 07:00
QString::count() does not make any sense in this context -- it counts the amount of occurrences of a pattern or character (or all characters). You could use resize, but you could also use left() or right(). Just have a look at those.

AlexSudnik
27th December 2010, 07:41
Hey,

there might be several options here. If your data is read from your device's stream then ,for instance,you can use QDataStream or QTextStream. Those have the propriate methods for reading data: QDataStream::readBytes and QTextStream::readLine,both take the length as an input parameter.

nagabathula
27th December 2010, 07:56
Hello sir this is what i did but not getting the right result.. Still some alignment problem.


QSqlQuery sq1("SELECT ChannelData FROM Bulkdb where rowid = " + QString::number(rowcnt));
while(sq1.next())
{
rowdata.push_back(sq1.value(0).toString());
}
for(int j = 0; j < rowdata.count(); j++) // All the data from Bulk BD which is in rowdata is appended to datstr
datstr.append(rowdata.at(j));
}
in the Next function i am trying to append 2944 chars to the comdata at a time. IS this right what i am doing sir.

comdata.append(datstr.right(2944));

newdat.append(comdata.mid(posi, 80));
posi+=92;
qDebug() << newdat;


i am using fromrawdata while retrieving the data from rs232 terminal.

QByteArray data = (QByteArray::fromRawData(buff,numBytes));

AlexSudnik
27th December 2010, 09:42
Wait a second,are you transmitting data from your device to the database or what? I mean,i don't quite understand succession of actions you take in the code snippet you've shared

And btw,there is no need to call me (is it?) sir,that's kinda weird:o:)

nagabathula
27th December 2010, 10:12
hello, i am actually receiving data from a embedded system on rs232 which i am retrieving and saving it into sq-lite db. once it is saved i am retrieving back the data from the bulkdb table in which it is present, for data alignment so that i have the actual channel data from the frame which i receive.. Everything is fine, when i retrieve back data the frame id is removed properly but by the time 2nd row in the db starts there is miss in the count and the data is not aligned properly.. so i though i will restrict the size of the QString to hold exactly 2944 chars, One Master frame has so many chars i.e Channel data with Frame id. So that i will have exactly one master frame data every time i do this frame id removing for one whole master frame.



datstr.resize(2944);
for(int j = 0; j < rowdata.count(); j++)
datstr.append(rowdata.at(j));

newdat.append(datstr.mid(posi, 80));
posi+=92;
datstr.clear();

but this code does't help me , after the first row of data aligning there is a problem..

thank you

wysota
27th December 2010, 12:55
You shouldn't be using QString. Use QByteArray instead. QString is for textual Unicode encoded data.