How to pass String Value in decimal to QlineEdit?
-
@Wasee said in How to pass String Value in decimal to QlineEdit?:
"sudo devmem2 0x80000000"
Do you realise that your string contains not only a number but allso non-number string ("sudo devmem2 ")?
That part of course can't be converted to a number.
You need first to extract the hex-number part and only convert that part to a number.
You can use https://doc.qt.io/qt-5/qstring.html#split to split your string using "0x" as separator.@jsulm
I think you need to clean your reading glasses and try again... ;-)The OP is using that string as argument to
QProcess::start()
, not as the string to parse!QProcess Temp_reading; std:: string ct_value=Temp_reading.start("sudo devmem2 0x80000000"); QString str (QString::fromStdString(ct_value));
void QProcess::start()
does not return any value, so this won't compile, will it....Can you just slow down a bit. What are you actually trying to do? I can only guess you have in mind:
Temp_reading.start("sudo devmem2 0x80000000"); Temp_reading.waitForFinished(); QString output(Temp_reading.readAllStandardOutput()); bool ok; int num = output.toInt(&ok, 0);
Actually I see you had this earlier. All you needed to do was do the
QString::toInt()
on what you got back followed byQString::number()
to put it into the line edit. And if that is delivering the right answer have a look at the output from the command which you are trying to parse.P.S.
You originally said the number you need to parse is (like)0x1
. I showed you the above code withoutput.toInt(&ok, 0);
is how to do that. If you are usingQString::toDouble()
as you show that will not work, as it cannot parse a leading0x
. -
@jsulm Hi;
I followed following code to split the string
/@
QString band1_2="sudo devmem2 0x80000000 w 0x";
QString str = QStringLiteral("sudo devmem2 0x80000000 w 0x");
QStringList list1 = str.split(QLatin1Char('.'));
qDebug()<<"Split:"<<list1;
@/
Its giving me value like "11". But it is not passing to lineedit why? Even I code to convert into integer below.
QString list;
bool ok;
int d;
d = Qstring(list).toInt(&ok);
ui->lineedit->setText(d);Thanks in advance
-
@jsulm Hi;
I followed following code to split the string
/@
QString band1_2="sudo devmem2 0x80000000 w 0x";
QString str = QStringLiteral("sudo devmem2 0x80000000 w 0x");
QStringList list1 = str.split(QLatin1Char('.'));
qDebug()<<"Split:"<<list1;
@/
Its giving me value like "11". But it is not passing to lineedit why? Even I code to convert into integer below.
QString list;
bool ok;
int d;
d = Qstring(list).toInt(&ok);
ui->lineedit->setText(d);Thanks in advance
@Wasee said in How to pass String Value in decimal to QlineEdit?:
QString list;
bool ok;
int d;
d = Qstring(list).toInt(&ok);This does not make sense at all: you create a string from an empty string (list) and then try to convert it to int.
Please read once more what I wrote. I never suggested to split using '."
But actually you should read what @JonB suggested, as my answer was based on my misunderstanding.
-
@jsulm
I think you need to clean your reading glasses and try again... ;-)The OP is using that string as argument to
QProcess::start()
, not as the string to parse!QProcess Temp_reading; std:: string ct_value=Temp_reading.start("sudo devmem2 0x80000000"); QString str (QString::fromStdString(ct_value));
void QProcess::start()
does not return any value, so this won't compile, will it....Can you just slow down a bit. What are you actually trying to do? I can only guess you have in mind:
Temp_reading.start("sudo devmem2 0x80000000"); Temp_reading.waitForFinished(); QString output(Temp_reading.readAllStandardOutput()); bool ok; int num = output.toInt(&ok, 0);
Actually I see you had this earlier. All you needed to do was do the
QString::toInt()
on what you got back followed byQString::number()
to put it into the line edit. And if that is delivering the right answer have a look at the output from the command which you are trying to parse.P.S.
You originally said the number you need to parse is (like)0x1
. I showed you the above code withoutput.toInt(&ok, 0);
is how to do that. If you are usingQString::toDouble()
as you show that will not work, as it cannot parse a leading0x
. -
@Wasee said in How to pass String Value in decimal to QlineEdit?:
.Please write piece of code
He already did.
What is not clear? -
@jsulm ;
Thanks!
But I am getting error of invalid conversion from int to const string for lineedit.ui->lineedit->setText(num);
-
@Wasee said in How to pass String Value in decimal to QlineEdit?:
Please provide exact information to do that
I will do once more your work, but last time now. I will not spend more of my time if you refuse to learn basics.
Go to https://doc.qt.io/qt-5/qlineedit.html#text-prop and check what the type is.
Type is QString.
C++ most basic knowledge: QString != int.
So, you can't pass an int as parameter to QLineEdit::setText, because setText() expects a QString.
I really fail to understand what is not clear about it?!
Maybe you should read a C++ book?Temp_reading.start("sudo devmem2 0x80000000"); Temp_reading.waitForFinished(); QString output(Temp_reading.readAllStandardOutput()); ui->lineedit->setText(output);
-
@jsulm Hi;
Its giving me Values continuous but I need to print these values after 0x in integer form in line-edit.
(0xb6f44000):0x11EACAC
(0xb6efe00):0x11EACAC
(0xb6fd4000):0x11EACAC
(0xb6fde000):0x11EACAC@Wasee What's wrong with https://doc.qt.io/qt-5/qstring.html#number-1?
d = Qstring(list).toInt(&ok, 16); // Since you handle hex numbers you need to tell toInt that it is a hex number - so pass 16 as base ui->lineedit->setText(QString::number(d));
-
Temp_reading.start("sudo devmem2 0x80000000"); Temp_reading.waitForFinished(); QString output(Temp_reading.readAllStandardOutput()); output = output.replace("(", "").replace(")", "").replace(":", ""); auto split = output.split("0x"); QString str("%1:%2"); str= str.arg(split.at(1).toLongLong(nullptr, 16)).arg(split.at(2).toLongLong(nullptr, 16)); ui->lineedit->setText(str);
-
@J-Hilk Hi;
I am still getting error "split does not name a type" and "split is not declare in this scope" and "nullptr was not declared in this scope"
thanks@Wasee said in How to pass String Value in decimal to QlineEdit?:
"nullptr was not declared in this scope"
impossible if you're using c++11 or later !
split does not name a type
either you forgot
auto
or you're really not using c++11. Split it is of type QStringList -
@J-Hilk Hi;
Problem solved but I need little bit change its giving me value 0:108280000, I didn't need 0: in this value how I can remove it.@Wasee said in How to pass String Value in decimal to QlineEdit?:
how I can remove it
How about doing what you already did in this thread: use split() method and ':' as split character.