How to print hexadecimal value in Textedit Qt Widget
-
Hi Everyone,
here i am confused with using lot of syntax in using can some one please help me.
i used simple code as below:void MainWindow::on_Status_Read_clicked() { char result=system("i2cget -f -y 0 0x24 0x05"); //reult is 0xa8 stored inside result variable QByteArray s = QByteArray::number(result,16).toUpper(); ui->textEdit->setText(s);//here expecting to print a value of 0xa8 but 0 is printing }
I am not getting what is issue even i tried like below
ui->textEdit->setText(result);//which given me syntax error
so if i tried like below also printing 0 only not 0xa8
void MainWindow::on_Status_Read_clicked() { int result=system("i2cget -f -y 0 0x24 0x05"); //reult is 0xa8 stored inside result variable QByteArray s = QByteArray::number(result,16).toUpper(); ui->textEdit->setText(s);//here expecting to print a value of 0xa8 but 0 is printing }
so someone please help me in printing the system function result in a widget.
Thanks & Regards
A.N.V.Lavanya -
Hi Everyone,
here i am confused with using lot of syntax in using can some one please help me.
i used simple code as below:void MainWindow::on_Status_Read_clicked() { char result=system("i2cget -f -y 0 0x24 0x05"); //reult is 0xa8 stored inside result variable QByteArray s = QByteArray::number(result,16).toUpper(); ui->textEdit->setText(s);//here expecting to print a value of 0xa8 but 0 is printing }
I am not getting what is issue even i tried like below
ui->textEdit->setText(result);//which given me syntax error
so if i tried like below also printing 0 only not 0xa8
void MainWindow::on_Status_Read_clicked() { int result=system("i2cget -f -y 0 0x24 0x05"); //reult is 0xa8 stored inside result variable QByteArray s = QByteArray::number(result,16).toUpper(); ui->textEdit->setText(s);//here expecting to print a value of 0xa8 but 0 is printing }
so someone please help me in printing the system function result in a widget.
Thanks & Regards
A.N.V.Lavanya@ananthavidhya Take a look at https://doc.qt.io/qt-5/qstring.html#arg-3 - it does exactly what you need (you just need to convert result to an integer first - https://doc.qt.io/qt-5/qstring.html#toInt).
-
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
u just need to convert result to a
Hi ,
Thanks for your response.
with your instructions i have changed my code as below:char result=system("i2cget -f -y 0 0x24 0x05"); bool ok; QString s = QString::number(result); int hex = s.toInt(&ok, 16); ui->textEdit->setText(hex);
but at ui-> line in code i am getting syntax error of reference to type 'const QString' could not bind to an value of type 'int'.
-
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
u just need to convert result to a
Hi ,
Thanks for your response.
with your instructions i have changed my code as below:char result=system("i2cget -f -y 0 0x24 0x05"); bool ok; QString s = QString::number(result); int hex = s.toInt(&ok, 16); ui->textEdit->setText(hex);
but at ui-> line in code i am getting syntax error of reference to type 'const QString' could not bind to an value of type 'int'.
@ananthavidhya
assuming result actually really stores 168 in it:int result=system("i2cget -f -y 0 0x24 0x05"); QString hexString = QString::number(result,16).toUpper(); ui->textEdit->setText(hexString);
and @jsulm told you to use the arg() function of QString:
QString str; str = QString("Decimal 63 is %1 in hexadecimal") .arg(63, 0, 16); // str == "Decimal 63 is 3f in hexadecimal"
-
Hi ,
I tried this above mentioned way too but still the result is 0 only.
trail1:char result=system("i2cget -f -y 0 0x24 0x05"); QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(result, 1, 16); ui->system->insertPlainText(str);
trail2:
int result=system("i2cget -f -y 0 0x24 0x05"); QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(result, 1, 16); ui->system->insertPlainText(str);
trail3:
QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(system("i2cget -f -y 0 0x24 0x05"), 1, 16); ui->system->insertPlainText(str);
all the above trails is resulting also showing as i2cget result is 0 in hexadecimal in plaintextedit widget i have taken in gui.
So it printing 0 only not 0x28 why? can some one suggest me on this please. -
Hi ,
I tried this above mentioned way too but still the result is 0 only.
trail1:char result=system("i2cget -f -y 0 0x24 0x05"); QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(result, 1, 16); ui->system->insertPlainText(str);
trail2:
int result=system("i2cget -f -y 0 0x24 0x05"); QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(result, 1, 16); ui->system->insertPlainText(str);
trail3:
QString str; str = QString("i2cget result is %1 in hexadecimal") .arg(system("i2cget -f -y 0 0x24 0x05"), 1, 16); ui->system->insertPlainText(str);
all the above trails is resulting also showing as i2cget result is 0 in hexadecimal in plaintextedit widget i have taken in gui.
So it printing 0 only not 0x28 why? can some one suggest me on this please.@ananthavidhya What does result contain?
Please addqDebug() << result;
after calling system() and tell us what you see.
-
This is the result of qDebug() << result after calling system()
int result=system("i2cget -f -y 0 0x24 0x05"); qDebug() << result;
Result in debug terminal:
root@am437x-evm:/home# ./Date_time
Using Wayland-EGL
wlpvr: PVR Services Initialised
0x28
0
0x28
0
so result is actually storing 0 value.. -
This is the result of qDebug() << result after calling system()
int result=system("i2cget -f -y 0 0x24 0x05"); qDebug() << result;
Result in debug terminal:
root@am437x-evm:/home# ./Date_time
Using Wayland-EGL
wlpvr: PVR Services Initialised
0x28
0
0x28
0
so result is actually storing 0 value..@ananthavidhya said in How to print hexadecimal value in Textedit Qt Widget:
so result is actually storing 0 value
That is your problem.
Are you sure i2cget does not simply return 0 as success?
I think the actual value you're reading is simply printed on stdout (that 0x28).
You will need to use QProcess and read stdout from the process to get the value. -
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
I think the actual value you're reading is simply printed on stdout (that 0x28).
you are right sir . if we click on the widget button it will print result on debug terminal as 0x28 which you are telling as standard output .
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
You will need to use QProcess and read stdout from the process to get the value.
Now reading the standard out printed in debug terminal is the one which we need to store in result using QProcess which i am i am not much aware of using this method so let me check it out and get back to you sir. but Thank you so much for your reply.
Now my hope raised a little bit. -
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
I think the actual value you're reading is simply printed on stdout (that 0x28).
you are right sir . if we click on the widget button it will print result on debug terminal as 0x28 which you are telling as standard output .
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
You will need to use QProcess and read stdout from the process to get the value.
Now reading the standard out printed in debug terminal is the one which we need to store in result using QProcess which i am i am not much aware of using this method so let me check it out and get back to you sir. but Thank you so much for your reply.
Now my hope raised a little bit.@ananthavidhya The easiest way would be to call process.readAll() after the process finishes - it will return everything the process printed to stdout.
-
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
The easiest way would be to call process.readAll() after the process finishes
If don't mind can you share me any good reference of Using QProcess through examples.
Thanks -
@jsulm said in How to print hexadecimal value in Textedit Qt Widget:
The easiest way would be to call process.readAll() after the process finishes
If don't mind can you share me any good reference of Using QProcess through examples.
Thanks@ananthavidhya There are examples in documentation: https://doc.qt.io/qt-5/qprocess.html
Especially this one is what you need:QProcess gzip; gzip.start("gzip", QStringList() << "-c"); if (!gzip.waitForStarted()) return false; if (!gzip.waitForFinished()) return false; QByteArray result = gzip.readAll();