New line in label with new data on serialport



  • 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.


  • Lifetime Qt Champion

    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



  • @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?



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


  • Moderators

    @Julian Add a new line:

    textEdit.appendPlainText("\n");
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.