LDS
5th May 2010, 16:18
Hello,
I'd like to convert a char array to a string so I can show it in a status label or a text edit box:
Example:
char temp[4] = {0x01, 0x03, 0x03, 0x04};
....
statusLabel->setText(QString::fromAscii(temp, 4));
The status label should show ideally 0x01 0x02 0x03 0x04.
I'm trying to do this in the fortune client example from Qt Creator.
void Client::readFortune()
{
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_3);
char temp[30];
int flag = 0;
char temp2[4] = {0x01, 0x02, 0x03, 0x04};
if (blockSize == 0) {
if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
flag = tcpSocket->readLine(temp, 31);// i'm trying to read the receive buffer here and show it below
if(flag |= -1){
messageLineEdit->setText(QString::number(blockSize)); // I can see the block size, 1537
statusLabel->setText(QString::fromAscii(temp2, 4));
}
if (tcpSocket->bytesAvailable() < blockSize)
return;
QString nextFortune;
in >> nextFortune;
if (nextFortune == currentFortune) {
QTimer::singleShot(0, this, SLOT(requestNewFortune()));
return;
}
currentFortune = nextFortune;
statusLabel->setText(currentFortune);
getFortuneButton->setEnabled(true);
}
I'd like to convert a char array to a string so I can show it in a status label or a text edit box:
Example:
char temp[4] = {0x01, 0x03, 0x03, 0x04};
....
statusLabel->setText(QString::fromAscii(temp, 4));
The status label should show ideally 0x01 0x02 0x03 0x04.
I'm trying to do this in the fortune client example from Qt Creator.
void Client::readFortune()
{
QDataStream in(tcpSocket);
in.setVersion(QDataStream::Qt_4_3);
char temp[30];
int flag = 0;
char temp2[4] = {0x01, 0x02, 0x03, 0x04};
if (blockSize == 0) {
if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
return;
in >> blockSize;
}
flag = tcpSocket->readLine(temp, 31);// i'm trying to read the receive buffer here and show it below
if(flag |= -1){
messageLineEdit->setText(QString::number(blockSize)); // I can see the block size, 1537
statusLabel->setText(QString::fromAscii(temp2, 4));
}
if (tcpSocket->bytesAvailable() < blockSize)
return;
QString nextFortune;
in >> nextFortune;
if (nextFortune == currentFortune) {
QTimer::singleShot(0, this, SLOT(requestNewFortune()));
return;
}
currentFortune = nextFortune;
statusLabel->setText(currentFortune);
getFortuneButton->setEnabled(true);
}