Add to QByteArray from TextBox
-
Hello, I have a lineEdit text box on my GUI Form which I plan to enter in a number such as float. I want to add the contents of the lineEdit box to a QByteArray.
Something like:
QByteArray data = QByteArray::number(ui->lineEdit_0->text());But when I try I get:
mainwindow.cpp:39: error: no matching function for call to 'QByteArray::number(QString)'
QByteArray data = QByteArray::number(ui->lineEdit_0->text());
^I intend to use the QByteArray to transmit UDP data:
udp->writeDatagram(data.data(),size,QHostAddress(this->ip),srcPort);Can anyone help out a newbie please.
Thank you
Joe -
Hello, I have a lineEdit text box on my GUI Form which I plan to enter in a number such as float. I want to add the contents of the lineEdit box to a QByteArray.
Something like:
QByteArray data = QByteArray::number(ui->lineEdit_0->text());But when I try I get:
mainwindow.cpp:39: error: no matching function for call to 'QByteArray::number(QString)'
QByteArray data = QByteArray::number(ui->lineEdit_0->text());
^I intend to use the QByteArray to transmit UDP data:
udp->writeDatagram(data.data(),size,QHostAddress(this->ip),srcPort);Can anyone help out a newbie please.
Thank you
JoeHi, and welcome!
@joe1652 said in Add to QByteArray from TextBox:
mainwindow.cpp:39: error: no matching function for call to 'QByteArray::number(QString)' QByteArray data = QByteArray::number(ui->lineEdit_0->text()); ^
QByteArray::number()
converts a number (int, float, double, etc.) to an 8-bit string. This is not what you want.QLineEdit::text()
returns aQString
. When you call this, your number is already stored a (16-bit) string.QString::toUtf8()
converts aQString
to aQByteArray
(using UTF-8 encoding)
-
Hello, thank you for responding to my message. I'm a little slow here.
QByteArray data = QByteArray:: what goes here (ui->lineEdit_0->text() );
Sorry to ask you again for help.