Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved New line in label with new data on serialport

    General and Desktop
    3
    5
    960
    Loading More Posts
    • 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.
    • Julian
      Julian last edited by

      Hello, I'm using Qt 5.5 and I use QSerialPort and it work fine!. The arduino send data from usb and I can just get the first line, this is because, the code is:

      void MainWindow::readData()
      {
      
      
          Buffer += serie->readAll();
      
          if(Buffer.size()==8)
          {
              n++;
               //Aca se debería llamar a la función que muestre en pantalla los datos
              this->Show();
              Buffer.clear();  //luego se limplia para los próximos datos,
              Buffer.resize(8);
          }
      
      
      }
      
      void MainWindow::Show()
      {
          int hora, min, seg;
          QString cadena1, cadena2, cadena3, cadena4, cadena5, cadena6,cadena7, cadena8;
          QString cadena, separacion;
      
          
          separacion=": ";
          cadena1="- Persona ingresada nº: ";
          cadena2=QString::number(n);
          cadena3=" Documento: ";
          cadena4=QString::fromLocal8Bit(Buffer);
      
          //obtenemos la hora
          hora=tiempo->hour();
          min=tiempo->minute();
          seg=tiempo->second();
      
          cadena5=" Hora";
      
          cadena6=QString::number(hora);
          cadena7=QString::number(min);
          cadena8=QString::number(seg);
      
          cadena=cadena1+cadena2+cadena3+cadena4+cadena5+separacion+cadena6+separacion+cadena7+separacion+cadena8;
       
          
          ui->label_2->setText(cadena);
      
      }
      
      

      Everytime that there is a next data on the port, the method readData is call. The method Show() show the data in the label.

      How Can I put another line in the label (label_2)?

      Because the next time that is a data on the port readData will be call and Show too but what I want is that the new date must be show in the next line of label_2.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Looks like you should rather be using a class like QPlainTextEdit. Otherwise you'll have to re-read the content of your QLabel each round and append what you received.

        Hope it helps

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Julian 2 Replies Last reply Reply Quote 0
        • Julian
          Julian @SGaist last edited by

          @Julian said:

          Buffer.clear(); //luego se limplia para los próximos datos,
          Buffer.resize(8);

          O thanks. But I thinks the Buffer no clear good, or is not deleted and created good. How can I do that?

          1 Reply Last reply Reply Quote 0
          • Julian
            Julian @SGaist last edited by

            @SGaist Sorry, but. How to make a line jump on text browser?

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @Julian last edited by

              @Julian Add a new line:

              textEdit.appendPlainText("\n");
              

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post