Solved How can i transfer Array to string?
-
HI, i'm using qt5.5 on my computer.
I wanna change the array to string.
This is my code.if(readData.toStdString()=="Hello world!") { ui->lineEditPT_ComportResult->setText("PASS"); ui->pushButtonPT_Comport_ResultLight->setStyleSheet("QPushButton{backgroo und-color:green;}"); ui->tableWidgetResult->item(4,0)->setBackgroundColor(Qt::green); ui->tableWidgetResult->item(4,1)->setBackgroundColor(Qt::green); save_Comport=1; if(save_Reset_Button & save_input & save_panel & save_LAN & save_LED & ss ave_LightSensor & save_Comport & save_USBOTG & save_USB) { ui->pushButtonPT_ResultSave->setEnabled(true); } ui->pushButtonPT_ComportSend->setText("OK"); }
readData is a QByteArray class and i want to compare the string "Hello world".
But when i compile it, it will show QByteArray has no member of .toStdString.
What can i do or what do i need to fix?
Please help! -
Try QString::fromAscii(readData.data())
-
Depending on ASCII or unicode codec you have
QString::fromLatin1;
and
QString::fromUtf8; QString::fromUtf16;
at your disposal. Both accept a QBytearray as input.
-
@vishnu
I can only find fromAscii_helper.
Why? -
@J.Hilk
I will try to use Latin1. -
@victor-wang Are you sure you're using Qt 5.5? The documentation http://doc.qt.io/qt-5/qbytearray.html#toStdString says:
"This function was introduced in Qt 5.4." -
Hi,
An additional question: why are you doing that useless conversion ?