Unsolved How can i show data that device sent in QT?
-
@J.Hilk
I modified it as you said but nothing changed.. -
@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 hereWell, you have all the information to make it work, then.
QByteArray datalog(mSerialport->readAll()); ui->datalog->setText(datalog);
-
@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 -
@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 dataSorry, 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.
-
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
-
@J.Hilk
invalid use of incomplete type ‘class QLineEdit’
QLineEdit * popUp = new QLineEdit();
error occured . Have I done anything wrong? -
@segtteee
add
#include <QLineEdit> -
@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());
^ -
@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());
-
@J.Hilk
thanks, it was not occured error after writing the code "connect(qApp,&QApplication::aboutToQuit,popUp,&QLineEdit::deleteLater);"