Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to convert QCharRef to hex, int, binary
Forum Updated to NodeBB v4.3 + New Features

how to convert QCharRef to hex, int, binary

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jsulm
    28 Oct 2019, 05:55

    @Mijaz said in how to convert QCharRef to hex, int, binary:

    First I want to read only "0x752F15A".

    Regular expressions are your friend: https://doc.qt.io/qt-5/qregularexpression.html

    M Offline
    M Offline
    Mijaz
    wrote on 28 Oct 2019, 06:51 last edited by
    #5

    @jsulm
    These are my questions.

    1. How I can read only "0x752F15A".?
    2. How I can convert this (0x752F15A) QCharRef into an equivalent binary.
    C J 2 Replies Last reply 28 Oct 2019, 06:55
    0
    • M Mijaz
      28 Oct 2019, 06:51

      @jsulm
      These are my questions.

      1. How I can read only "0x752F15A".?
      2. How I can convert this (0x752F15A) QCharRef into an equivalent binary.
      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 28 Oct 2019, 06:55 last edited by
      #6

      @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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • M Mijaz
        28 Oct 2019, 06:51

        @jsulm
        These are my questions.

        1. How I can read only "0x752F15A".?
        2. How I can convert this (0x752F15A) QCharRef into an equivalent binary.
        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 28 Oct 2019, 06:55 last edited by
        #7

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        4
        • J jsulm
          28 Oct 2019, 05:55

          @Mijaz said in how to convert QCharRef to hex, int, binary:

          First I want to read only "0x752F15A".

          Regular expressions are your friend: https://doc.qt.io/qt-5/qregularexpression.html

          M Offline
          M Offline
          Mijaz
          wrote on 30 Oct 2019, 10:16 last edited by
          #8

          @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;

          1. 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:

          1. qint64 Bandwith_full = Bandwith_freq.toInt(&ok2,10); converts string to integer correctly
          2. qint64 my_LO = LO_current.toInt(&ok3,10); retruns '0' but why?

          Selection_030.png

          J 1 Reply Last reply 30 Oct 2019, 10:19
          0
          • M Mijaz
            30 Oct 2019, 10:16

            @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;

            1. 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:

            1. qint64 Bandwith_full = Bandwith_freq.toInt(&ok2,10); converts string to integer correctly
            2. qint64 my_LO = LO_current.toInt(&ok3,10); retruns '0' but why?

            Selection_030.png

            J Online
            J Online
            J.Hilk
            Moderators
            wrote on 30 Oct 2019, 10:19 last edited by
            #9

            @Mijaz because 2 475 000 000 > 2 147 483 647 (max int_32t)-> to int failed


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            M 1 Reply Last reply 30 Oct 2019, 10:21
            1
            • J J.Hilk
              30 Oct 2019, 10:19

              @Mijaz because 2 475 000 000 > 2 147 483 647 (max int_32t)-> to int failed

              M Offline
              M Offline
              Mijaz
              wrote on 30 Oct 2019, 10:21 last edited by Mijaz
              #10

              @J-Hilk
              2^32= 4294967296 > 2475000000

              but I used qint64

              https://doc.qt.io/qt-5/qtglobal.html#qint64-typedef

              J 1 Reply Last reply 30 Oct 2019, 10:27
              0
              • M Mijaz
                30 Oct 2019, 10:21

                @J-Hilk
                2^32= 4294967296 > 2475000000

                but I used qint64

                https://doc.qt.io/qt-5/qtglobal.html#qint64-typedef

                J Online
                J Online
                J.Hilk
                Moderators
                wrote on 30 Oct 2019, 10:27 last edited by
                #11

                @Mijaz just because you assign the result to a qint64 doesn't mean that toInt() returns a qint64.

                toLongLong returns a int64


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                M 1 Reply Last reply 30 Oct 2019, 10:28
                2
                • J J.Hilk
                  30 Oct 2019, 10:27

                  @Mijaz just because you assign the result to a qint64 doesn't mean that toInt() returns a qint64.

                  toLongLong returns a int64

                  M Offline
                  M Offline
                  Mijaz
                  wrote on 30 Oct 2019, 10:28 last edited by
                  #12

                  @J-Hilk
                  then, what is the solution?

                  J 1 Reply Last reply 30 Oct 2019, 10:29
                  0
                  • M Mijaz
                    30 Oct 2019, 10:28

                    @J-Hilk
                    then, what is the solution?

                    J Online
                    J Online
                    J.Hilk
                    Moderators
                    wrote on 30 Oct 2019, 10:29 last edited by
                    #13

                    @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


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    M 1 Reply Last reply 30 Oct 2019, 10:33
                    1
                    • J J.Hilk
                      30 Oct 2019, 10:29

                      @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

                      M Offline
                      M Offline
                      Mijaz
                      wrote on 30 Oct 2019, 10:33 last edited by
                      #14

                      @J-Hilk
                      Thank you very much. it works

                      1 Reply Last reply
                      1

                      14/14

                      30 Oct 2019, 10:33

                      • Login

                      • Login or register to search.
                      14 out of 14
                      • First post
                        14/14
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved