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. Extend format specifier?
Forum Updated to NodeBB v4.3 + New Features

Extend format specifier?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.1k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Thomas R. Krenn
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      Why not just:

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

      for that to work you need to include:

      #include <QDebug>
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        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.

        1 Reply Last reply
        0
        • jsulmJ jsulm

          Why not just:

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

          for that to work you need to include:

          #include <QDebug>
          
          T Offline
          T Offline
          Thomas R. Krenn
          wrote on last edited by
          #4

          @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

          mrjjM 1 Reply Last reply
          0
          • T Thomas R. Krenn

            @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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0

            • Login

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