Results 1 to 3 of 3

Thread: escaped string problem

  1. #1
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default escaped string problem

    I have different types of kiosk printers for different purposes but i want to have a single printer class
    the idea is tho store string like this in database
    "\x1B\x40\x1B\x21\x28\x1B\x61\x31\nText line with %1 parameters\nand %2 something"
    the first few characters initialize printer and set options (for different printers different initialization)

    1. I need to load this string from database
    2. convert escaped sequences ( "\x1B" becomes single character 27)
    3. process parameter text (%1 is replaced with string)
    4. write the result to serial port and to get ticket

    Is this proper way or someone knows a better solution?
    Anway i am stuck at task no. 2, how to process part of string that represents escape sequence
    i have no idea how to do this task
    I am using qt5 with c++11 config so new features of language are welcome
    some google results pointed to toRaw and fromRaw functions but
    to be honest i dont know how to present this problem with "multi level escape usage"

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: escaped string problem

    If you need the strings to be user readable then that is as good an encoding as any other, although you may find URL percent encoding easier to work with because Qt provides QByteArray::fromPercentEncoding() and its inverse. If the binary data does not need to be user readable then you can simply store it unencoded in a blob column or, if your database cannot do a blob, then QByteArray::toBase64() may be useful.

  3. The following user says thank you to ChrisW67 for this useful post:

    davidovv (31st January 2013)

  4. #3
    Join Date
    Dec 2009
    Posts
    65
    Thanks
    10
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: escaped string problem

    wanted string to simplify modification, advanced user needs only database connection
    so both blob and toBase64() are out
    i searched for function that loads string like compiler does but
    QByteArray::fromPercentEncoding() is all I need
    thanks again

Similar Threads

  1. Replies: 3
    Last Post: 17th April 2012, 16:05
  2. Strange Qt 4.4.0 string problem
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2008, 06:46
  3. Problem with std::string's
    By Rayven in forum General Programming
    Replies: 1
    Last Post: 17th July 2007, 18:29
  4. problem converting string-char-int
    By mickey in forum General Programming
    Replies: 1
    Last Post: 9th December 2006, 23:43
  5. QT string Find problem
    By kingslee in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 20:45

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.