PDA

View Full Version : custom QDebug and add new QtMsgType type



ArnSpin
13th February 2015, 11:44
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

#ifndef MYDEBUG_H
#define MYDEBUG_H

#include <QObject>
#include <QWidget>
#include <QDebug>

class myDebug :public QDebug
{
Q_OBJECT
public:
myDebug();
~myDebug();

};

#endif // MYDEBUG_H

mydebug.cpp

#include "mydebug.h"

myDebug::myDebug()
{

}

myDebug::~myDebug()
{

}


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 :)

anda_skoa
13th February 2015, 12:21
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



myDebug::myDebug() : QDebug(....)
{
}


Cheers,
_

ArnSpin
13th February 2015, 12:38
Ok, very clear Thanks a lot.

anda_skoa
13th February 2015, 15:55
You might also want to have a look at category based logging: http://doc.qt.io/qt-5/qloggingcategory.html

Cheers,
_