Solved how to convert QCharRef to hex, int, binary
-
@jsulm
Header: #include <QRegularExpression>
qmake: QT += core
Since: Qt 5.0I am using qt4.8.7
-
@Mijaz Is there a question in your last post?
Please post at least an understandable question if you want to get meaningful answers!
If you use Qt4 then use https://doc.qt.io/archives/qt-4.8/qregexp.html -
@jsulm
These are my questions.- How I can read only "0x752F15A".?
- How I can convert this (0x752F15A) QCharRef into an equivalent binary.
-
@Mijaz said in how to convert QCharRef to hex, int, binary:
How I can read only "0x752F15A".?
As @jsulm already told you with QRegExp or with QByteArray/QString string modification functions: e.g. https://doc.qt.io/archives/qt-4.8/qstring.html#indexOf
How I can convert this (0x752F15A) QCharRef into an equivalent binary.
QString has functions for it: https://doc.qt.io/archives/qt-4.8/qstring.html#toInt
-
@Mijaz said in how to convert QCharRef to hex, int, binary:
How I can read only "0x752F15A".?
Please learn how to use regular expressions. This is something a programmer should know.
For the second question: see https://doc.qt.io/qt-5/qstring.html#toInt
-
@jsulm
QProcess frq_bw;
frq_bw.start("cat /sys/bus/iio/devices/iio:device1/out_voltage_rf_bandwidth");
frq_bw.waitForFinished(-1); // will wait forever until finished
QString Bandwith_freq = frq_bw.readAllStandardOutput();
qDebug() << "current bandwith integer" << Bandwith_freq;
bool ok2;- qint64 Bandwith_full = Bandwith_freq.toInt(&ok2,10);
int Bandwith_half=Bandwith_full/2;
qDebug()<<"current half Bandwith integer = " << QString::number(Bandwith_half);
// bandwidth cat and half it
QProcess curr_lo;
curr_lo.start("cat /sys/bus/iio/devices/iio:device1/out_altvoltage0_RX_LO_frequency");
curr_lo.waitForFinished(-1); // will wait forever until finished
QString LO_current = curr_lo.readAllStandardOutput();
qDebug() << "current LO =" << LO_current;
bool ok3;
2) qint64 my_LO = LO_current.toInt(&ok3,10);
qDebug() << "Current LO integer = " << my_LO ;Problem:
- qint64 Bandwith_full = Bandwith_freq.toInt(&ok2,10); converts string to integer correctly
- qint64 my_LO = LO_current.toInt(&ok3,10); retruns '0' but why?
- qint64 Bandwith_full = Bandwith_freq.toInt(&ok2,10);
-
@Mijaz because 2 475 000 000 > 2 147 483 647 (max int_32t)-> to int failed
-
@J-Hilk
2^32= 4294967296 > 2475000000but I used qint64
-
@Mijaz just because you assign the result to a qint64 doesn't mean that toInt() returns a qint64.
toLongLong returns a int64
-
@J-Hilk
then, what is the solution? -
@Mijaz said in how to convert QCharRef to hex, int, binary:
@J-Hilk
then, what is the solution?@J-Hilk said in how to convert QCharRef to hex, int, binary:
toLongLong returns a int64
-
@J-Hilk
Thank you very much. it works