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 print hexadecimal value in Textedit Qt Widget
Forum Updated to NodeBB v4.3 + New Features

How to print hexadecimal value in Textedit Qt Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.3k 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.
  • A Offline
    A Offline
    ananthavidhya
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • A ananthavidhya

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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).

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

      1 Reply Last reply
      4
      • A Offline
        A Offline
        ananthavidhya
        wrote on last edited by ananthavidhya
        #3

        @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'.

        J.HilkJ 1 Reply Last reply
        0
        • A ananthavidhya

          @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'.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

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

          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.

          1 Reply Last reply
          2
          • A Offline
            A Offline
            ananthavidhya
            wrote on last edited by ananthavidhya
            #5

            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.

            jsulmJ 1 Reply Last reply
            0
            • A ananthavidhya

              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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ananthavidhya What does result contain?
              Please add

              qDebug() << result;
              

              after calling system() and tell us what you see.

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ananthavidhya
                wrote on last edited by ananthavidhya
                #7

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

                jsulmJ 1 Reply Last reply
                0
                • A ananthavidhya

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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

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

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

                  1 Reply Last reply
                  2
                  • A Offline
                    A Offline
                    ananthavidhya
                    wrote on last edited by
                    #9

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

                    jsulmJ 1 Reply Last reply
                    0
                    • A ananthavidhya

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

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @ananthavidhya The easiest way would be to call process.readAll() after the process finishes - it will return everything the process printed to stdout.

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

                      1 Reply Last reply
                      2
                      • A Offline
                        A Offline
                        ananthavidhya
                        wrote on last edited by ananthavidhya
                        #11

                        @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

                        jsulmJ 1 Reply Last reply
                        0
                        • A ananthavidhya

                          @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

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

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

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

                          1 Reply Last reply
                          2

                          • Login

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