Results 1 to 7 of 7

Thread: QString resize() or count()

  1. #1
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default QString resize() or count()

    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.

    Qt Code:
    1. QString sq("INSERT INTO Bulkdb values(%1, %2)");
    2. sq = sq.arg(rcount)
    3. .arg("'" + stfram + "'");
    4. m_query.exec(sq);
    5. rcount++;
    6. stfram.clear();
    To copy to clipboard, switch view to plain text mode 

    thank you

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QString resize() or count()

    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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString resize() or count()

    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.

  4. #4
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: QString resize() or count()

    Hello sir this is what i did but not getting the right result.. Still some alignment problem.
    Qt Code:
    1. QSqlQuery sq1("SELECT ChannelData FROM Bulkdb where rowid = " + QString::number(rowcnt));
    2. while(sq1.next())
    3. {
    4. rowdata.push_back(sq1.value(0).toString());
    5. }
    6. for(int j = 0; j < rowdata.count(); j++) // All the data from Bulk BD which is in rowdata is appended to datstr
    7. datstr.append(rowdata.at(j));
    8. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Qt Code:
    1. comdata.append(datstr.right(2944));
    2.  
    3. newdat.append(comdata.mid(posi, 80));
    4. posi+=92;
    5. qDebug() << newdat;
    To copy to clipboard, switch view to plain text mode 

    i am using fromrawdata while retrieving the data from rs232 terminal.
    QByteArray data = (QByteArray::fromRawData(buff,numBytes));

  5. #5
    Join Date
    Dec 2010
    Location
    Russia
    Posts
    83
    Thanks
    1
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString resize() or count()

    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

  6. #6
    Join Date
    Nov 2010
    Posts
    100
    Thanks
    38
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4

    Default Re: QString resize() or count()

    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.

    Qt Code:
    1. datstr.resize(2944);
    2. for(int j = 0; j < rowdata.count(); j++)
    3. datstr.append(rowdata.at(j));
    4.  
    5. newdat.append(datstr.mid(posi, 80));
    6. posi+=92;
    To copy to clipboard, switch view to plain text mode 
    datstr.clear();

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

    thank you

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString resize() or count()

    You shouldn't be using QString. Use QByteArray instead. QString is for textual Unicode encoded data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    nagabathula (29th December 2010)

Similar Threads

  1. Count number of Characters
    By TJSonic in forum Newbie
    Replies: 7
    Last Post: 14th November 2010, 20:39
  2. QThread count in Qt applications.
    By hashimov in forum Qt Programming
    Replies: 21
    Last Post: 22nd October 2010, 13:41
  3. [QGLWidget] Count FPS
    By Macok in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 14:01
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. Replies: 2
    Last Post: 22nd January 2008, 16:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.