Problem with QString and QByteArray
Hi all,
Im am working on a program and have problems with handling a QByteArray string.
When I try to convert that QByteArray string to a QString with
I do get the following error:
Code:
/usr
/include
/QtCore
/qchar.
h:372:8: note
: candidates are
: QChar::QChar(int) <near match>
/usr
/include
/QtCore
/qchar.
h:371:8: note
: QChar::QChar(uint
) <near match>
/usr
/include
/QtCore
/qchar.
h:370:8: note
: QChar::QChar(short int) <near match>
/usr
/include
/QtCore
/qchar.
h:81:12: note
: QChar::QChar(ushort
) <near match>
/usr
/include
/QtCore
/qchar.
h:77:36: note
: QChar::QChar(uchar
) <near match>
/usr
/include
/QtCore
/qchar.
h:76:36: note
: QChar::QChar(char) <near match>
The newQString is the output of a script of me and should be a plain text string.
What is going wrong here?
Code Snippet:
myclass.cpp
Code:
void myclass::Thefunction(){
// QProcess *scriptcall; pointer declared as a public member in the class header file
scriptcall -> start("./myscript");
connect(scriptcall, SIGNAL(readyReadStandardOutput()), this, SLOT(Readoutput()));
}
void myclass::Readoutput(){
oldQByteArrayString = scriptcall -> readAllStandardOutput();
QString newQString
= QString(&oldQByteArrayString
);
//this line causes the error
}
Additional Information: I can use oldQByteArrayString with a function that requires QSTtring as a parameter without a problem. (QComboBox::addItem( const QString)). When I look at the hex code of oldQByteArray, it contains exactly what I want to be there - 4 ascii code letters, no special chars.
Re: Problem with QString and QByteArray
Take the & off from here:
QString newQString = QString(&oldQBytearrayString); -> QString newQString = QString(oldQBytearrayString);
and it should work. A shorter form should also work: QString newQString(oldQBytearrayString);
Re: Problem with QString and QByteArray
Why do you want to pass an address of QByteArray to QString constructor ?
This will work :