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. format stream output
Qt 6.11 is out! See what's new in the release blog

format stream output

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 774 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    hi
    with this code

       qDebug()<< reMatch.captured(1)  << " : " << reMatch.captured(2)
                        << "; DIAM : " <<  reMatch.captured(3)
                        << "; LT : "  << reMatch.captured(4)
                        << "; LU : "  << reMatch.captured(5);
    

    the output is

    "T1"  :  "BOULE" ; DIAM :  "10" ; LT :  "111" ; LU :  "80"
    "T2"  :  "CYL" ; DIAM :  "11" ; LT :  "112" ; LU :  "81"
    "T3"  :  "DROIT" ; DIAM :  "12" ; LT :  "113" ; LU :  "82"
    "T4"  :  "CON" ; DIAM :  "13" ; LT :  "114" ; LU :  "83"
    

    how can i have an output where DIAM LT LU are correctly aligned ?

    "T1"  :  "BOULE"; DIAM :  "10"; LT :  "111"; LU :  "80"
    "T2"  :  "CYL";   DIAM :  "11"; LT :  "112"; LU :  "81"
    "T3"  :  "DROIT"; DIAM :  "12"; LT :  "113"; LU :  "82"
    "T4"  :  "CON";   DIAM :  "13"; LT :  "114"; LU :  "83"
    
    JonBJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      use \t instead of spaces

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ODБOïO 1 Reply Last reply
      3
      • ODБOïO ODБOï

        hi
        with this code

           qDebug()<< reMatch.captured(1)  << " : " << reMatch.captured(2)
                            << "; DIAM : " <<  reMatch.captured(3)
                            << "; LT : "  << reMatch.captured(4)
                            << "; LU : "  << reMatch.captured(5);
        

        the output is

        "T1"  :  "BOULE" ; DIAM :  "10" ; LT :  "111" ; LU :  "80"
        "T2"  :  "CYL" ; DIAM :  "11" ; LT :  "112" ; LU :  "81"
        "T3"  :  "DROIT" ; DIAM :  "12" ; LT :  "113" ; LU :  "82"
        "T4"  :  "CON" ; DIAM :  "13" ; LT :  "114" ; LU :  "83"
        

        how can i have an output where DIAM LT LU are correctly aligned ?

        "T1"  :  "BOULE"; DIAM :  "10"; LT :  "111"; LU :  "80"
        "T2"  :  "CYL";   DIAM :  "11"; LT :  "112"; LU :  "81"
        "T3"  :  "DROIT"; DIAM :  "12"; LT :  "113"; LU :  "82"
        "T4"  :  "CON";   DIAM :  "13"; LT :  "114"; LU :  "83"
        
        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @LeLev
        Is your output going to somewhere with a fixed-width font, else it's going to be problematic?

        Assuming it is, you can use @VRonin's \ts, or you pre-format the string with width specifiers (must be somewhere in QString) before passing to qDebug().

        1 Reply Last reply
        1
        • VRoninV VRonin

          use \t instead of spaces

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @VRonin thank you very much

                  qDebug()<< reMatch.captured(1)
                              << ":"
                              << reMatch.captured(2) << "\t"
                              << "DIAM :"
                              <<  reMatch.captured(3)<<";"
                              << "LT :"
                              << reMatch.captured(4)<<";"
                              << "LU :"
                              << reMatch.captured(5)<<";";
          

          @JonB said in format stream output:

          width specifiers

          i will take a look at that also thank you!

          JonBJ 1 Reply Last reply
          0
          • ODБOïO ODБOï

            @VRonin thank you very much

                    qDebug()<< reMatch.captured(1)
                                << ":"
                                << reMatch.captured(2) << "\t"
                                << "DIAM :"
                                <<  reMatch.captured(3)<<";"
                                << "LT :"
                                << reMatch.captured(4)<<";"
                                << "LU :"
                                << reMatch.captured(5)<<";";
            

            @JonB said in format stream output:

            width specifiers

            i will take a look at that also thank you!

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @LeLev
            https://doc.qt.io/qt-5/qstring.html#arg is the overload you want for strings, use fieldWidth argument (negative number if you want left-aligned as per your example). Tabs are quick and work till they don't (depends on number of characters determining where the next tab stop is).

            1 Reply Last reply
            1

            • Login

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