PDA

View Full Version : Problem with QString and QByteArray



ts66
10th May 2011, 21:13
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

QString newQString = QString(&oldQBytearrayString);
I do get the following error:


error: conversion from ‘QByteArray*’ to ‘QChar’ is ambiguous
/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



void myclass::Thefunction(){

// QProcess *scriptcall; pointer declared as a public member in the class header file
scriptcall = new QProcess(this);
scriptcall -> start("./myscript");

connect(scriptcall, SIGNAL(readyReadStandardOutput()), this, SLOT(Readoutput()));

}

void myclass::Readoutput(){

QByteArray oldQByteArrayString;
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.

mvuori
10th May 2011, 21:27
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);

stampede
10th May 2011, 21:30
Why do you want to pass an address of QByteArray to QString constructor ?
This will work :

QString newQString = QString(oldQBytearrayString);