Results 1 to 9 of 9

Thread: from c++ to pyqt4 QByteArray

  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 from c++ to pyqt4 QByteArray

    hi i have this block of code in c++ how to convert it to pyqt4

    virtual QByteArray myMapper() const {
    assert(0); return QByteArray(256, 0);
    }

    const QByteArray& sequence = QByteArray("ABCDESFGTTTTTT");
    const char* opq = sequence.data() +55;
    QByteArray map =myMapper() ;

    for(int i=0;i< sequence.size(); i++) {
    char rdf= opq[i];
    char cl = map.at(rdf)

    }

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: from c++ to pyqt4 QByteArray

    is it your intention that this pointer

    const char* opq = sequence.data() +55;

    be invalid? It points to memory outside of the string - you are later reading random memory addresses...

    This also looks nonsensical
    Qt Code:
    1. for(int i=0;i< sequence.size(); i++) {
    2. char rdf= opq[i];
    3. char cl = map.at(rdf)
    4. }
    To copy to clipboard, switch view to plain text mode 
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #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: from c++ to pyqt4 QByteArray

    Quote Originally Posted by amleto View Post
    is it your intention that this pointer

    const char* opq = sequence.data() +55;

    be invalid? It points to memory outside of the string - you are later reading random memory addresses...

    This also looks nonsensical
    Qt Code:
    1. for(int i=0;i< sequence.size(); i++) {
    2. char rdf= opq[i];
    3. char cl = map.at(rdf)
    4. }
    To copy to clipboard, switch view to plain text mode 
    i know im concern the conversion and 55 is an example for any int
    this is the real code
    const QByteArray& sequence = detView->getSequenceContext()->getSequenceData();
    const char* seq = sequence.data() + detView->getVisibleRange().startPos;

    DNATranslation* complTrans = detView->getComplementTT();
    QByteArray map = complTrans->getOne2OneMapper();
    int y = getTextY(complementLine);
    for(int i=0;i< visibleRange.len; i++) {
    char nucl = seq[i];
    char complNucl = map.at(nucl);
    }

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: from c++ to pyqt4 QByteArray

    sigh. Next time please be more wary of wasting people's time with nonsense code. Also use code tags!
    I still don't understand what this is meant to be doing
    Qt Code:
    1. char nucl = seq[i];
    2. char complNucl = map.at(nucl); // map.at takes an int - why is a char being passed here? You get trouble if char is signed and a negative number...
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. def myMapper(self):
    2. return QByteArray(256, 0)
    3.  
    4. sequence = QByteArray("ABCDESFGTTTTTT")
    5. some_sensible_number = 3 # this is just an example...
    6. opq = sequence.mid(some_sensible_number).data()
    7. map = myMapper()
    8.  
    9. for i in range(__visible_range__): # visible range, not sequence.size() as you tried to fool us with
    10. rdf = opq.at(i)
    11. cl = map.at(ord(rdf)) # guessing ord is ok, might not be
    To copy to clipboard, switch view to plain text mode 
    Last edited by amleto; 6th December 2012 at 17:42.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

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

    Default Re: from c++ to pyqt4 QByteArray

    Quote Originally Posted by alrawab View Post
    hi i have this block of code in c++ how to convert it to pyqt4

    virtual QByteArray myMapper() const {
    assert(0); return QByteArray(256, 0);
    }

    const QByteArray& sequence = QByteArray("ABCDESFGTTTTTT");
    const char* opq = sequence.data() +55;
    QByteArray map =myMapper() ;

    for(int i=0;i< sequence.size(); i++) {
    char rdf= opq[i];
    char cl = map.at(rdf)

    }
    Maybe you should start by explaining what your code is supposed to be doing at all? I can see this is related to encoding some DNA sequence but as it was already said, the code doesn't make much sense.
    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.


  6. #6
    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: from c++ to pyqt4 QByteArray

    thanks amleto
    as you tried to fool us with => its an example i will handle the real range
    the problem is when you do
    map = myMapper()
    you will get this error in python :
    return QByteArray(256, 0)
    TypeError: arguments did not match any overloaded call:
    QByteArray(): too many arguments
    QByteArray(int, str): argument 2 has unexpected type 'int'
    QByteArray(QByteArray): argument 1 has unexpected type 'int'

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

    Default Re: from c++ to pyqt4 QByteArray

    Try passing '\0' as the second argument to the constructor.
    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. #8
    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: from c++ to pyqt4 QByteArray

    its pyqt4 realated so can you solve this
    why i got such a message
    return QByteArray(256, 0)
    TypeError: arguments did not match any overloaded call:
    QByteArray(): too many arguments
    QByteArray(int, str): argument 2 has unexpected type 'int'
    QByteArray(QByteArray): argument 1 has unexpected type 'int'

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

    Default Re: from c++ to pyqt4 QByteArray

    I already told you, the constructor for the byte array expects a string instead of an int as its second argument. You have all you need in the error message.
    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.


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

    alrawab (7th December 2012)

Similar Threads

  1. Replies: 0
    Last Post: 5th August 2012, 01:03
  2. Replies: 1
    Last Post: 22nd June 2011, 08:12
  3. [PyQt4] PyQt4 + gcin issue
    By fieliapm in forum Installation and Deployment
    Replies: 0
    Last Post: 28th September 2010, 08:04
  4. Replies: 9
    Last Post: 25th July 2009, 13:27
  5. Need Help for PyQt4
    By JAIDEEP KANDELWAL in forum Qt Programming
    Replies: 0
    Last Post: 22nd April 2009, 23:08

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.