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. How can i show data that device sent in QT?
Forum Updated to NodeBB v4.3 + New Features

How can i show data that device sent in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 4.1k 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.
  • S segtteee

    @sierdzio
    Thank you for your reply.
    I add the code
    void MainWindow::readSerialData()
    {
    QByteArray datalog(mSerialport->readAll());
    }
    at the end and excute, but I did not see anything in datalog,QT.
    Is there any way I can get the data as in the third picture?

    sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #5

    @segtteee said in How can i show data that device sent in QT?:

    at the end and excute, but I did not see anything in datalog,QT.
    Is there any way I can get the data as in the third picture?

    You are not setting it in the UI anywhere. What you written only took the serial data and saved it into a (local) datalog variable. Which is then discarded when the function gets out of scope. You need to set the contents (or formatted contents like @J-Hilk has shown) on some UI element you have - QLabel, QTextEdit etc. We don't know what are the names of your UI components so we can't help you write that code, at least no more than:

    QByteArray datalog(mSerialport->readAll());
    ui->someLabelOrTextField->setText(datalog);
    

    (Z(:^

    S 1 Reply Last reply
    1
    • sierdzioS sierdzio

      @segtteee said in How can i show data that device sent in QT?:

      at the end and excute, but I did not see anything in datalog,QT.
      Is there any way I can get the data as in the third picture?

      You are not setting it in the UI anywhere. What you written only took the serial data and saved it into a (local) datalog variable. Which is then discarded when the function gets out of scope. You need to set the contents (or formatted contents like @J-Hilk has shown) on some UI element you have - QLabel, QTextEdit etc. We don't know what are the names of your UI components so we can't help you write that code, at least no more than:

      QByteArray datalog(mSerialport->readAll());
      ui->someLabelOrTextField->setText(datalog);
      
      S Offline
      S Offline
      segtteee
      wrote on last edited by
      #6

      @sierdzio
      sorry.. my ui is mainwindow.ui and port is mSerialport .
      textedit object's name is datalog , I would like to see the data here

      sierdzioS 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @segtteee we still don't know in what form your data arrives.

        Here's a general, quick & dirty way to convert your raw data - byte by byte - into a nicely formated user readable hex -string, that you than can send to one of your ui-Elements.

        void MainWindow::readSerialData()
        {
        QString s;
        QByteArray datalog(mSerialport->readAll());
        for(int i = 0; i < datalog.size(); i++)
                s.append(QString::number(static_cast<unsigned char>(datalog[i]),16).toUpper().rightJustified(2,'0')+ " ");
        }
        
        
        S Offline
        S Offline
        segtteee
        wrote on last edited by
        #7

        @J.Hilk
        I modified it as you said but nothing changed..

        1 Reply Last reply
        0
        • S segtteee

          @sierdzio
          sorry.. my ui is mainwindow.ui and port is mSerialport .
          textedit object's name is datalog , I would like to see the data here

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #8

          @segtteee said in How can i show data that device sent in QT?:

          @sierdzio
          sorry.. my ui is mainwindow.ui and port is mSerialport .
          textedit object's name is datalog , I would like to see the data here

          Well, you have all the information to make it work, then.

          QByteArray datalog(mSerialport->readAll());
          ui->datalog->setText(datalog);
          

          (Z(:^

          S 1 Reply Last reply
          1
          • sierdzioS sierdzio

            @segtteee said in How can i show data that device sent in QT?:

            @sierdzio
            sorry.. my ui is mainwindow.ui and port is mSerialport .
            textedit object's name is datalog , I would like to see the data here

            Well, you have all the information to make it work, then.

            QByteArray datalog(mSerialport->readAll());
            ui->datalog->setText(datalog);
            
            S Offline
            S Offline
            segtteee
            wrote on last edited by
            #9

            @sierdzio
            void readSerialData() {
            QByteArray reply(mSerialport->readAll());
            // put reply to your UI. I don't know your UI component names so I won't write it down
            }
            What you say here "reply" is what I think. I think it is object's name like combo box , push-button or text edit.
            So I thought the reply was datalog , which object I want to view the data

            sierdzioS 1 Reply Last reply
            0
            • S segtteee

              @sierdzio
              void readSerialData() {
              QByteArray reply(mSerialport->readAll());
              // put reply to your UI. I don't know your UI component names so I won't write it down
              }
              What you say here "reply" is what I think. I think it is object's name like combo box , push-button or text edit.
              So I thought the reply was datalog , which object I want to view the data

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #10

              @segtteee said in How can i show data that device sent in QT?:

              @sierdzio
              void readSerialData() {
              QByteArray reply(mSerialport->readAll());
              // put reply to your UI. I don't know your UI component names so I won't write it down
              }
              What you say here "reply" is what I think. I think it is object's name like combo box , push-button or text edit.
              So I thought the reply was datalog , which object I want to view the data

              Sorry, but I don't understand you comment at all.

              In QByteArray reply, the "reply" is only a name of a local variable (defined inside the function). It has no relation to any other part of your program, not until you make it related by passing it to some other function or control. I hope that explanation helps you, I'm not sure, your replies are very confusing to me.

              (Z(:^

              1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @segtteee we still don't know in what form your data arrives.

                Here's a general, quick & dirty way to convert your raw data - byte by byte - into a nicely formated user readable hex -string, that you than can send to one of your ui-Elements.

                void MainWindow::readSerialData()
                {
                QString s;
                QByteArray datalog(mSerialport->readAll());
                for(int i = 0; i < datalog.size(); i++)
                        s.append(QString::number(static_cast<unsigned char>(datalog[i]),16).toUpper().rightJustified(2,'0')+ " ");
                }
                
                
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #11

                We still don't know what you have in your ui-file, so here a solution without one:

                void MainWindow::readSerialData()
                {
                QString s;
                QByteArray datalog(mSerialport->readAll());
                for(int i = 0; i < datalog.size(); i++)
                s.append(QString::number(static_cast<unsigned char>(datalog[i]),16).toUpper().rightJustified(2,'0')+ " ");

                QLineEdit * popUp = new QLineEdit();
                popUp->setReadOnly(true);
                popUp->setText(s);
                popUp->show();

                //cleanup
                popUp->setAttribute(Qt::WA_DeleteOnClose,true);
                connect(qApp, &QApplication::aboutToQuit, popUp, QLineEdit::deleteLater);
                }

                Edit: deleted double show call


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                S 1 Reply Last reply
                2
                • J.HilkJ J.Hilk

                  We still don't know what you have in your ui-file, so here a solution without one:

                  void MainWindow::readSerialData()
                  {
                  QString s;
                  QByteArray datalog(mSerialport->readAll());
                  for(int i = 0; i < datalog.size(); i++)
                  s.append(QString::number(static_cast<unsigned char>(datalog[i]),16).toUpper().rightJustified(2,'0')+ " ");

                  QLineEdit * popUp = new QLineEdit();
                  popUp->setReadOnly(true);
                  popUp->setText(s);
                  popUp->show();

                  //cleanup
                  popUp->setAttribute(Qt::WA_DeleteOnClose,true);
                  connect(qApp, &QApplication::aboutToQuit, popUp, QLineEdit::deleteLater);
                  }

                  Edit: deleted double show call

                  S Offline
                  S Offline
                  segtteee
                  wrote on last edited by
                  #12

                  @J.Hilk
                  invalid use of incomplete type ‘class QLineEdit’
                  QLineEdit * popUp = new QLineEdit();
                  error occured . Have I done anything wrong?

                  J.HilkJ 1 Reply Last reply
                  0
                  • S segtteee

                    @J.Hilk
                    invalid use of incomplete type ‘class QLineEdit’
                    QLineEdit * popUp = new QLineEdit();
                    error occured . Have I done anything wrong?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #13

                    @segtteee
                    add
                    #include <QLineEdit>


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    S 1 Reply Last reply
                    1
                    • J.HilkJ J.Hilk

                      @segtteee
                      add
                      #include <QLineEdit>

                      S Offline
                      S Offline
                      segtteee
                      wrote on last edited by
                      #14

                      @J.Hilk
                      It was resolved but another error occurred.
                      ../myserial/mainwindow.cpp:102:76: error: cannot call member function ‘void QObject::deleteLater()’ without object
                      connect(qApp, &QApplication::aboutToQuit,popUp, QLineEdit::deleteLater());
                      ^

                      J.HilkJ 1 Reply Last reply
                      0
                      • S segtteee

                        @J.Hilk
                        It was resolved but another error occurred.
                        ../myserial/mainwindow.cpp:102:76: error: cannot call member function ‘void QObject::deleteLater()’ without object
                        connect(qApp, &QApplication::aboutToQuit,popUp, QLineEdit::deleteLater());
                        ^

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #15

                        @segtteee said in How can i show data that device sent in QT?:

                        @J.Hilk
                        It was resolved but another error occurred.
                        ../myserial/mainwindow.cpp:102:76: error: cannot call member function ‘void QObject::deleteLater()’ without object
                        connect(qApp, &QApplication::aboutToQuit,popUp, QLineEdit::deleteLater());
                        ^

                        Thats a typing mistake from my side.

                        connect(qApp, &QApplication::aboutToQuit,popUp, &QLineEdit::deleteLater());


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        S 1 Reply Last reply
                        1
                        • J.HilkJ J.Hilk

                          @segtteee said in How can i show data that device sent in QT?:

                          @J.Hilk
                          It was resolved but another error occurred.
                          ../myserial/mainwindow.cpp:102:76: error: cannot call member function ‘void QObject::deleteLater()’ without object
                          connect(qApp, &QApplication::aboutToQuit,popUp, QLineEdit::deleteLater());
                          ^

                          Thats a typing mistake from my side.

                          connect(qApp, &QApplication::aboutToQuit,popUp, &QLineEdit::deleteLater());

                          S Offline
                          S Offline
                          segtteee
                          wrote on last edited by
                          #16

                          @J.Hilk
                          thanks, it was not occured error after writing the code "connect(qApp,&QApplication::aboutToQuit,popUp,&QLineEdit::deleteLater);"

                          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