QCommandLineParser: help-text looks ugly



  • Hi,

    in my console app I'm using the QCommandLineParser. Basically it is working, but somehow the output of the parser does not look nice, e.g. if I type the help-option the whole text is written in one row and the linebreaks can be seen in the text. So formatting of the text, which is done by Qt, does not work.

    Has it something to do with the cmd-Window (on Windows 10)? But even in the Creator-output-window the text looks ugly. What is wrong?

    Thanks in advance,
    Kai


  • Qt Champions 2016

    Hi
    Maybe some pictures+code would help ?
    Im not sure what u see and how u you produce the output ( bad looking one)
    Also state qt ver.

    I dont have any answer, just trying to raise ur chance of good replies :)



  • OK,

    the Qt ver is 5.7beta. The use of the QCommandLineParser is pretty standard, like the example-code. The output looks like this:

    The following command:
    D:\Temp\build\ImageRename-Desktop_Qt_5_7_0_MSVC2015_64bit-Debug\debug>ImageRename.exe --help

    Produces this output (one row):
    "Usage: ImageRename.exe [options] directory\nRename files inside of a directory.\n\nOptions:\n -?, -h, --help Displays this help.\n -v, --version Displays version information.\n\nArguments:\n directory Directory containing
    the files which should be renamed.\n"

    I think the problem is that the linebreaks (\n), which are there are not "executed".


  • Qt Champions 2016

    @kaivolde said:

    Produces this output (one row):
    "Usage: ImageRename.exe [options] directory\nRename files inside of a directory.\n\nOptions:\n -?, -h, --help Displays this help.\n -v, --version Displays version information.\n\nArguments:\n directory Directory containing
    the files which should be renamed.\n"

    What's the exact line that you use for printing the help text? I'd just yesterday used that particular class and it worked perfectly fine on my machine (Linux 4,4 kernel, Qt 5.5.1). It looks like the newlines are not recognized as such (Windows actually uses the \r\n sequence for a newline).


  • Lifetime Qt Champion

    Hi,

    If using qDebug, then there was a change in the way qDebug's output is formatted. You can find more information about it in this email thread



  • @SGaist: Yes I do the output with qDebug (and its variants):
    (impressed getting an answer from the Qt Champion, congrats btw.)

    if ( parser.isSet( helpOption )) {
        qDebug() << parser.helpText();
        exit( 0 );
    }
    

    Unfortunately I don't find a solution in the thread or is the solution not to use qDebug at all?


  • Qt Champions 2016

    @kaivolde

    QTextStream out(stdout);
    out << parser.helpText();
    

    Should serve you just fine. Also, don't call ::exit (if that's the C exit() function) without a good reason. If you're in main return the code. If you have a running application, call the quit slot.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.