Results 1 to 2 of 2

Thread: How to define string of QLoggingCategory during runtime?

  1. #1
    Join Date
    Aug 2012
    Posts
    18
    Thanks
    4
    Qt products
    Platforms
    Unix/X11 Windows

    Default How to define string of QLoggingCategory during runtime?

    Hello,

    I've read the docs, searched the forum and the web, but I am still confused or it is not possible.

    I've been working on a little private application, that has multiple worker threads. These workers process something on a specific physical drive, e.g. Worker A on drive "E:" and Worker B on drive "F:". Only a single worker can work with a specific drive. During processing, these workers produce some logging output which should preferrably not go into a single log file. I'd like to have a separate log file, so that everything related to drive "E:" is logged in its own log file.

    Here, QLoggingCategory seems to be the right way. I could use the string parameter of Q_LOGGING_CATEGORY as the drive name. But as it seems, by doing
    Qt Code:
    1. Q_DECLARE_LOGGING_CATEGORY(foo)
    2. Q_LOGGING_CATEGORY(foo, "bar")
    To copy to clipboard, switch view to plain text mode 
    "bar" cannot be defined during runtime. Only after startup the application knows for sure, what drives are available on the machine. Especially, when there are many removable drives in use. As it is now, the syntax forces me to define the string before I compile the source.

    Is there a way, how I can use the logging system of Qt (qInfo, qDebug, etc.) with category strings set during runtime? What kind of alternative can I use, if it is not feasable?
    I can think of embedding special tags in the log message itself and react on them in the message handler, but that already feels like an evil hack while typing it. ;-)

    Andreas

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to define string of QLoggingCategory during runtime?

    Q_LOGGIN_CATEGORY is just a macro.

    If you look at how it is defined, you'll see that it simply passes the second argument to the QLoggingCategory constructor.

    The function around is just a technique to safely create a globally accessible object.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    antimatter (1st June 2016)

Similar Threads

  1. Using QLoggingCategory, rules precedence seem backwards
    By don@thegagnes.com in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2014, 18:17
  2. How to define a string marco in pro file
    By jevonwang in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 6th May 2013, 05:49
  3. How to define a string in a .pro file
    By ChristineD in forum Newbie
    Replies: 4
    Last Post: 16th October 2012, 17:14
  4. Replies: 1
    Last Post: 25th September 2010, 08:20
  5. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.