I have a char array and want to convert one of the values from char to qstring:
unsigned char inBuffer[64];
....
QString str= QString(*inBuffer[1]);
ui->counter->setText(str);
This isn't working (I get a compiler error). Any suggestions?
Please check http://qt-project.org/doc/qt-4.8/qstring.html
QString & operator+= ( char ch )
QString & operator= ( char ch )
You can use operator+= to append a char, or operator= to assign a char.
But in your code it will call constructor, not operator=. There is no constructor for char, so your code can not compile.
QString str;
str = inBuffer[1];
QString has a constructor
QString ( QChar ch )
So u can use following code to do that
QString str= QChar(inBuffer[1]);
or
QString str(QChar(inBuffer[1]));
This is the easiest way to do that:
QString x="";
QChar y='a';
x+=y;
So here you have a QString with the char.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With