format stream output
-
wrote on 26 Nov 2019, 09:52 last edited by ODБOï
hi
with this codeqDebug()<< 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"
-
wrote on 26 Nov 2019, 10:22 last edited by
use
\t
instead of spaces -
hi
with this codeqDebug()<< 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"
wrote on 26 Nov 2019, 10:38 last edited by JonB@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
\t
s, or you pre-format the string with width specifiers (must be somewhere inQString
) before passing toqDebug()
. -
wrote on 26 Nov 2019, 10:43 last edited by
@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!
-
@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!
wrote on 26 Nov 2019, 10:47 last edited by JonB@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/5