Results 1 to 8 of 8

Thread: Reversing QString and QByteArray

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Reversing QString and QByteArray

    hi
    What is the best way to get reverse of QString and QByteArray (fast and safe) with out using loops (it becomes very slow with huge data)
    thanks
    Br
    Sis

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Reversing QString and QByteArray

    If you don't want to maintain loops, then may be you can maintain a copy of reverse. I mean a parallel copy. Each time you do an append on the string, do the similar reversed operation of the other copy. Tricky
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    alrawab (12th January 2013)

  4. #3
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reversing QString and QByteArray

    yes it a good idea but i'm dealing with dna sequences .
    i'm using :
    for( QByteArray::const_iterator i = myqbyte.constEnd(); i !=myqbyte.constBegin(); )
    but this procedure become so slow with large sequences

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Reversing QString and QByteArray

    DNA

    I were to do so, I would write a customized container for DNA strand/sequence, (This will need knowledge of DNA structure and ways to digitize it)

    There are other methods, but are applciation specific, like reverse only the section of the sequence? (instead of complete sequence).

    Think again do you really want to reverse the sequence? can you not re-write your operation to operate on the sequence in reverse (I bet that should be acceptable)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  6. #5
    Join Date
    May 2008
    Location
    Tripoli Libya
    Posts
    70
    Thanks
    10
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reversing QString and QByteArray

    this is my function which do the reverse task (some time i need to get the reverse of the full length )
    //--------------------------------------
    // Returns the reverse strand of a DNA or RNA sequence.
    QByteArray QDnaSequence::Reverse(QByteArray& seq)
    {
    QByteArray reverse;
    for( QByteArray::const_iterator i = seq.constEnd(); i !=seq.constBegin(); )
    {
    --i;
    reverse += *i;
    }
    return reverse;
    }

Similar Threads

  1. Get QByteArray from QString
    By Coder5546 in forum Newbie
    Replies: 1
    Last Post: 21st December 2012, 18:03
  2. QByteArray to Qstring
    By bmps in forum Qt Programming
    Replies: 6
    Last Post: 16th November 2011, 20:02
  3. QByteArray to QString
    By hvitual in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2009, 10:43
  4. QByteArray to QString
    By babu198649 in forum Newbie
    Replies: 7
    Last Post: 6th December 2007, 13:08
  5. How to get QByteArray from QString in Qt3
    By joseph in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2007, 09:23

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.