Results 1 to 4 of 4

Thread: custom QDebug and add new QtMsgType type

  1. #1
    Join Date
    Feb 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default custom QDebug and add new QtMsgType type

    Hi everybody,

    I'am pretty new on Qt and honestly I don't have an extraordinary level in c++.

    I try to implement my own debug function.
    I already created a system allowing to retrieve debug messages in a QTextEdit (there is some useful example on the web), I would like now to be able to do some tests on these debug messages.

    For example, I would like to add a level indicating if the message corresponds to a position in the code (e.g. "i am in the function toto", its level would be 0), or a intermediate results (level 1) in my calculations, or a main result (lvl 2) etc.
    I would be able to display message in function of level or to associate colors in the Qtextedit etc. I know there is several kind of debug messages: debug, warning, critical, fatal... I would like to have this kind of things.
    An elegant solution could be to refine the QtMsgType type (debug, warning,...) and add new but I don't know how to do.

    So I try to create my own class inherited from QDebug and after that I will surcharge operator <<.

    mydebug.h
    Qt Code:
    1. #ifndef MYDEBUG_H
    2. #define MYDEBUG_H
    3.  
    4. #include <QObject>
    5. #include <QWidget>
    6. #include <QDebug>
    7.  
    8. class myDebug :public QDebug
    9. {
    10. Q_OBJECT
    11. public:
    12. myDebug();
    13. ~myDebug();
    14.  
    15. };
    16.  
    17. #endif // MYDEBUG_H
    To copy to clipboard, switch view to plain text mode 

    mydebug.cpp
    Qt Code:
    1. #include "mydebug.h"
    2.  
    3. myDebug::myDebug()
    4. {
    5.  
    6. }
    7.  
    8. myDebug::~myDebug()
    9. {
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    Problem is, I have the compile error: error: C2512: 'QDebug' : no appropriate default constructor available
    I spent too much time to search the answer... so I modestly ask your help.
    In addition, better ideas / advices on what I want to do are welcoming.

    Thank you very much

  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: custom QDebug and add new QtMsgType type

    You are deriving from QDebug.
    Your constructor does not chain to one of the QDebug constructors, so the compiler tries to invoke the default constructor.
    But QDebug has no default constructor (constructor without arguments).

    You'll need to chain-call one of the available constructors

    Qt Code:
    1. myDebug::myDebug() : QDebug(....)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

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

    ArnSpin (13th February 2015)

  4. #3
    Join Date
    Feb 2015
    Posts
    4
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: custom QDebug and add new QtMsgType type

    Ok, very clear Thanks a lot.

  5. #4
    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: custom QDebug and add new QtMsgType type

    You might also want to have a look at category based logging: http://doc.qt.io/qt-5/qloggingcategory.html

    Cheers,
    _

Similar Threads

  1. Custom Type Sending
    By iprion in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2013, 11:19
  2. QVariant with Custom Type
    By kasmanit in forum Qt Programming
    Replies: 4
    Last Post: 2nd September 2012, 17:02
  3. QTreeView with custom type
    By jajdoo in forum Newbie
    Replies: 1
    Last Post: 25th September 2011, 20:27
  4. Replies: 13
    Last Post: 6th May 2011, 10:34
  5. Replies: 0
    Last Post: 9th September 2009, 02:35

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.