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 convert int to string with 2 fields?
Forum Update on Monday, May 27th 2025

How convert int to string with 2 fields?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 678 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.
  • E Offline
    E Offline
    Enrique82
    wrote on 22 Aug 2019, 12:44 last edited by
    #1

    I need to convert numbers to string, but with 2 fields, for examples:

    If int num=1, I need Qstring txt = "01"
    If int num=23, I need Qstring txt = "23"

    Thanks

    J 1 Reply Last reply 22 Aug 2019, 12:57
    0
    • E Enrique82
      22 Aug 2019, 12:44

      I need to convert numbers to string, but with 2 fields, for examples:

      If int num=1, I need Qstring txt = "01"
      If int num=23, I need Qstring txt = "23"

      Thanks

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 22 Aug 2019, 12:57 last edited by
      #2

      @enrique82

      that's like super easy to google 🤔
      https://stackoverflow.com/questions/2618414/convert-an-int-to-a-qstring-with-zero-padding-leading-zeroes

      QString number = QString("%1").arg(yourNumber, 2, 10, QChar('0'));
      

      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
      3
      • E Offline
        E Offline
        Enrique82
        wrote on 22 Aug 2019, 13:57 last edited by
        #3

        Thanks, I couldn't find it in google

        P 1 Reply Last reply 22 Aug 2019, 14:45
        0
        • E Enrique82
          22 Aug 2019, 13:57

          Thanks, I couldn't find it in google

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 22 Aug 2019, 14:45 last edited by
          #4

          @enrique82 if your issue is solved, please don't forget to mark your post as such! Thanks

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          3/4

          22 Aug 2019, 13:57

          • Login

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