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 pass String Value in decimal to QlineEdit?

How to pass String Value in decimal to QlineEdit?

Scheduled Pinned Locked Moved Unsolved General and Desktop
33 Posts 6 Posters 5.6k 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.
  • WaseeW Offline
    WaseeW Offline
    Wasee
    wrote on last edited by
    #20

    @jsulm Hi;
    Its giving me value 0 in my lineedit.

    jsulmJ 1 Reply Last reply
    0
    • WaseeW Wasee

      @jsulm Hi;
      Its giving me value 0 in my lineedit.

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

      @Wasee That means that the conversion from string to int failed. I'm now out of this thread. Debug your code to see what happens and fix the issues...

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

      1 Reply Last reply
      0
      • J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #22
        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);
        

        alt text


        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
        • WaseeW Offline
          WaseeW Offline
          Wasee
          wrote on last edited by
          #23

          @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

          J.HilkJ 1 Reply Last reply
          0
          • WaseeW Wasee

            @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

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

            @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


            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
            0
            • WaseeW Offline
              WaseeW Offline
              Wasee
              wrote on last edited by
              #25

              @J-Hilk Hi;
              how I can solve this issue?

              J.HilkJ 1 Reply Last reply
              0
              • WaseeW Wasee

                @J-Hilk Hi;
                how I can solve this issue?

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

                @Wasee add c++11 to your compiler call


                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
                0
                • WaseeW Offline
                  WaseeW Offline
                  Wasee
                  wrote on last edited by
                  #27

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

                  jsulmJ J.HilkJ 2 Replies Last reply
                  0
                  • WaseeW Wasee

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

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

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

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

                    1 Reply Last reply
                    0
                    • WaseeW Wasee

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

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

                      @Wasee
                      the magic happens here

                      QString str("%1:%2");
                      str= str.arg(split.at(1).toLongLong(nullptr, 16)).arg(split.at(2).toLongLong(nullptr, 16));
                      

                      do you see, what is happening?

                      assuming your result from the external process is of the format
                      (0xb6f44000):0x11EACAC

                      like you wrote earlier.
                      than splitwill contain

                      output = output.replace("(", "").replace(")", "").replace(":", "");
                      auto split = output.split("0x");
                      // index 0 = ""
                      //index 1 = "b6f44000"
                      //index 2 = "11EACAC"
                      

                      so depending on what value you want, you want index 1 or 2 therefore

                      ui->lineedit->setText(QString::number(split.at(index1or2),16);
                      

                      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
                      • WaseeW Offline
                        WaseeW Offline
                        Wasee
                        wrote on last edited by
                        #30

                        @J-Hilk Hi;
                        Its giving me index1or2 declaration error here.
                        thanks

                        jsulmJ 1 Reply Last reply
                        0
                        • WaseeW Wasee

                          @J-Hilk Hi;
                          Its giving me index1or2 declaration error here.
                          thanks

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

                          @Wasee said in How to pass String Value in decimal to QlineEdit?:

                          index1or2

                          Come on - this is just a placeholder. You need to replace it with either index1 or index2...

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

                          1 Reply Last reply
                          2
                          • WaseeW Offline
                            WaseeW Offline
                            Wasee
                            wrote on last edited by
                            #32

                            @jsulm Hi;
                            When I placed this code:
                            /@
                            ui->lineedit->setText(QString::number(split.at(index1or2),16);
                            @/

                            Its giving me error again of invalid conversion.
                            Simply tell me how I can convert it into integer of following external value.
                            /@jsulm
                            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));

                            @/
                            just convert it into integer value.

                            jsulmJ 1 Reply Last reply
                            0
                            • WaseeW Wasee

                              @jsulm Hi;
                              When I placed this code:
                              /@
                              ui->lineedit->setText(QString::number(split.at(index1or2),16);
                              @/

                              Its giving me error again of invalid conversion.
                              Simply tell me how I can convert it into integer of following external value.
                              /@jsulm
                              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));

                              @/
                              just convert it into integer value.

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

                              @Wasee said in How to pass String Value in decimal to QlineEdit?:

                              Simply tell me how I can convert it into integer of following external value

                              You already was told how and @J-Hilk even gave you code.
                              If it does not work then please be so kind and analyse what happens. This is what a developer should do in such a situation.
                              What does split.at(index1) or split.at(index2) return? Does it return a string containing a valid hex number?

                              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