Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help with Text Browser
Qt 6.11 is out! See what's new in the release blog

Help with Text Browser

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 555 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joe306
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • J joe306

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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]));
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        joe306
        wrote on last edited by
        #3

        Hello, thank you very much for responding to my message. That solved my problem.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved