Results 1 to 13 of 13

Thread: easiest Way QString can do

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: easiest Way QString can do

    Using QRegExp:
    Qt Code:
    1. QRegExp rx(":([0-9A-F]{2})([0-9A-F]{4})([0-9A-F]{2})([0-9A-F]*)([0-9A-F]{2})");
    2. QString str = "...";
    3. QStringList fields;
    4. if(rx.exactMatch(str)) fields = rx.capturedTexts();
    To copy to clipboard, switch view to plain text mode 

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

    baray98 (15th April 2008)

  3. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    111
    Thanked 4 Times in 4 Posts

    Default Re: easiest Way QString can do

    What about QByteArray? While reading file you can fill the instance of it ...
    Qt 5.3 Opensource & Creator 3.1.2

  4. #3
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: easiest Way QString can do

    QRegExp is good ,i am not too familiar with it (need some work on my part ) . If you guys can lead me the way on how to break
    dd is a data field that represents one byte of data.
    into pairs using QRegExp I will highly appreciate it

    reading the tricks of QRegExp,

    baray98

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

    Default Re: easiest Way QString can do

    What do you want to break here? If you have to characters in a string that represents a hexadecimal number, use QString::toInt() and you're done.

  6. #5
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: easiest Way QString can do

    I am trying to break the data line into bytes
    Qt Code:
    1. fields.at(3) // data of the hex line
    To copy to clipboard, switch view to plain text mode 
    from the code below

    Qt Code:
    1. QRegExp rx(":([0-9A-F]{2})([0-9A-F]{4})([0-9A-F]{2})([0-9A-F]*)([0-9A-F]{2})");QString str = "...";QStringList fields;if(rx.exactMatch(str)) fields = rx.capturedTexts();
    To copy to clipboard, switch view to plain text mode 

    baray98

  7. #6
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: easiest Way QString can do

    Qt Code:
    1. QRegExp rx(":([0-9A-F]{2})([0-9A-F]{4})([0-9A-F]{2})([0-9A-F]*)([0-9A-F]{2})");
    2. QString str = "...";
    3. QStringList fields;
    4. if(rx.exactMatch(str)) fields = rx.capturedTexts();
    To copy to clipboard, switch view to plain text mode 

    sorry i mess up my cut and paste in the prior reply

    baray98

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

    Default Re: easiest Way QString can do

    Qt Code:
    1. QString str = fields.at(3);
    2. for(int i=0;i<str.size();i+=2)
    3. qDebug() << str.mid(i,2).toInt(0, 16);
    To copy to clipboard, switch view to plain text mode 

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

    baray98 (15th April 2008)

Similar Threads

  1. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 21:47
  2. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 18:59
  3. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 23:10
  4. Replies: 2
    Last Post: 10th February 2006, 13:57
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 21:41

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.