Help with Text Browser
-
Hello, I'm a QT newbie so this is problem an easy question for the members. I have a UDP application and I am able to receive packets and would like to print the received data to a Text Browser but I don't know how to cast the integer array "my_array" in order to be printed in the Text Browser.
void MainWindow::processDatagram()
{
int size = 1440;
int my_array[1440] = {0};
int static frame_cntr = 0;
char value =0;
QByteArray buffer(size, value);
while(udp->hasPendingDatagrams())
{
udp->readDatagram(buffer.data(),size);
}
QDataStream in(&buffer, QIODevice::ReadOnly);ui->textBrowser->append("New UDP Packet received \n"); for(int i = 0; i<size; i++) in >> my_array[i]; for(int i = 0; i<size; i++) { ui->textBrowser->append(QString().setNum(my_array[i])); } ui->textBrowser->append(buffer.toHex()); ui->textBrowser->append(QString(frame_cntr++)); ui->textBrowser->append("\n");}
The problem I need help with is line:
ui->textBrowser->append(QString().setNum(my_array[i]));How do I cast the my_array so that it will be printed in the textBrowser?
Thanks
Joe -
Hello, I'm a QT newbie so this is problem an easy question for the members. I have a UDP application and I am able to receive packets and would like to print the received data to a Text Browser but I don't know how to cast the integer array "my_array" in order to be printed in the Text Browser.
void MainWindow::processDatagram()
{
int size = 1440;
int my_array[1440] = {0};
int static frame_cntr = 0;
char value =0;
QByteArray buffer(size, value);
while(udp->hasPendingDatagrams())
{
udp->readDatagram(buffer.data(),size);
}
QDataStream in(&buffer, QIODevice::ReadOnly);ui->textBrowser->append("New UDP Packet received \n"); for(int i = 0; i<size; i++) in >> my_array[i]; for(int i = 0; i<size; i++) { ui->textBrowser->append(QString().setNum(my_array[i])); } ui->textBrowser->append(buffer.toHex()); ui->textBrowser->append(QString(frame_cntr++)); ui->textBrowser->append("\n");}
The problem I need help with is line:
ui->textBrowser->append(QString().setNum(my_array[i]));How do I cast the my_array so that it will be printed in the textBrowser?
Thanks
Joe@joe306 said in Help with Text Browser:
ui->textBrowser->append(QString().setNum(my_array[i]));
If you check QString documentation you will find: https://doc.qt.io/qt-5/qstring.html#number-1
So, it is simply:ui->textBrowser->append(QString::number(my_array[i]));