View Full Version : from c++ to pyqt4 QByteArray
alrawab
6th December 2012, 13:31
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)
}
amleto
6th December 2012, 14:11
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
for(int i=0;i< sequence.size(); i++) {
char rdf= opq[i];
char cl = map.at(rdf)
}
alrawab
6th December 2012, 14:51
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
for(int i=0;i< sequence.size(); i++) {
char rdf= opq[i];
char cl = map.at(rdf)
}
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);
}
amleto
6th December 2012, 18:28
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
char nucl = seq[i];
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...
def myMapper(self):
return QByteArray(256, 0)
sequence = QByteArray("ABCDESFGTTTTTT")
some_sensible_number = 3 # this is just an example...
opq = sequence.mid(some_sensible_number).data()
map = myMapper()
for i in range(__visible_range__): # visible range, not sequence.size() as you tried to fool us with
rdf = opq.at(i)
cl = map.at(ord(rdf)) # guessing ord is ok, might not be
wysota
6th December 2012, 21:07
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.
alrawab
7th December 2012, 07:17
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'
wysota
7th December 2012, 07:46
Try passing '\0' as the second argument to the constructor.
alrawab
7th December 2012, 08:14
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'
wysota
7th December 2012, 08:38
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.