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. New line in label with new data on serialport
Forum Updated to NodeBB v4.3 + New Features

New line in label with new data on serialport

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.3k Views 1 Watching
  • 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.
  • JulianJ Offline
    JulianJ Offline
    Julian
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      JulianJ 2 Replies Last reply
      0
      • SGaistS SGaist

        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

        JulianJ Offline
        JulianJ Offline
        Julian
        wrote on last edited by
        #3

        @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
        0
        • SGaistS SGaist

          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

          JulianJ Offline
          JulianJ Offline
          Julian
          wrote on last edited by
          #4

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

          jsulmJ 1 Reply Last reply
          0
          • JulianJ Julian

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

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

            @Julian Add a new line:

            textEdit.appendPlainText("\n");
            

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

            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