Extend format specifier?



  • Hello everyboy!
    Now we have to write:

    qInfo("Current Working Directory: %s", QDir::currentPath().toUtf8().constData());

    how about:

    qInfo("Current Working Directory: %S", QDir::currentPath());

    Note the capital S in the format specifier. This would make the code easier to read and would also save us a toUtf8 and fromUtf8.


  • Moderators

    Why not just:

    qInfo() << "Current Working Directory: " << QDir::currentPath();
    

    for that to work you need to include:

    #include <QDebug>
    

  • Qt Champions 2016

    hi and welcome
    This is user forum so not many of the devs
    hang out here so suggestion will often just vanish into the darkness.
    to talk to the devs, you can subscribe to one of
    http://lists.qt-project.org/mailman/listinfo

    If you dream of it now , you could use a function
    qInfo("Current Working Directory: %s", ex( QDir::currentPath() ));
    Using refs, the price would be small.



  • @jsulm Thanks for the hint, I tried that but the << op has some default formatting that I don't always want. The code is also a lot harder to read if there is a longer list of parameters and formatting options.

    Anyway, I really appreciate that we can now redirect the output using:
    QtMsgHandler qInstallMsgHandler ( QtMsgHandler handler )

    best regards
    thomas


  • Qt Champions 2016

    @Thomas-R.-Krenn
    yeah I must confess the i still like "%d" style better
    than << if more than a few values even its not type safe.
    I found a type safe version of printf i tend to misuse :)
    yes qInstallMsgHandler is really handy.


Log in to reply
 

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