gpuckett
16th May 2015, 14:48
I am developing an application using Qt Creator. It is version 3.1.2 based on Qt 5.3.1 (MSVC 2010, 32bit) running on Win 7. I have been working on this project for about 9 months. Before that I had no experience with Qt and almost none with C++. So I'm very inexperienced with resolving some issues I run into. This is one of them.
I picked up some code a few months ago that allows me to put the output of QDebug in a file rather than the console. I added it to a project at the time and it worked great. I am now attempting to put the same code in a new project and I am encountering build errors. The code goes in the main.cpp module. Here is the code:
#define MY_ASSERT(c) if (c == false) ;
#define MY_ASSERT_X(c, where, what) if (c == false) ;
void myLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QFile file("E:/temp/logs/QDebug."+QDate::currentDate().toString("yyyyMMdd")+".log.txt");
MY_ASSERT(file.open(QIODevice::Append | QIODevice::Text));
QTextStream out(&file);
out << QTime::currentTime().toString("hh:mm:ss.zzzz ");
out << context.file << "::" << context.function << "::" << context.line;
switch (type)
{
case QtDebugMsg: out << " DBG "; break;
case QtWarningMsg: out << " WRN "; break;
case QtCriticalMsg: out << " CRT "; break;
case QtFatalMsg: out << " FTL "; break;
}
out << " " << msg << '\n';
out.flush();
}
And then in the function main I put
qInstallMessageHandler(myLogger);
In the new project I get the following errors:
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: warning: C4003: not enough actual parameters for macro 'min'
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: error: C2589: '(' : illegal token on right side of '::'
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: error: C2059: syntax error : '::'
The main difference between the two projects is that the one that works is a console application and uses QCoreApplication. The one that doesn't work is a widgets application and uses QApplication.
What do I need to do to get this code in the QWidgets application to work?
I picked up some code a few months ago that allows me to put the output of QDebug in a file rather than the console. I added it to a project at the time and it worked great. I am now attempting to put the same code in a new project and I am encountering build errors. The code goes in the main.cpp module. Here is the code:
#define MY_ASSERT(c) if (c == false) ;
#define MY_ASSERT_X(c, where, what) if (c == false) ;
void myLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QFile file("E:/temp/logs/QDebug."+QDate::currentDate().toString("yyyyMMdd")+".log.txt");
MY_ASSERT(file.open(QIODevice::Append | QIODevice::Text));
QTextStream out(&file);
out << QTime::currentTime().toString("hh:mm:ss.zzzz ");
out << context.file << "::" << context.function << "::" << context.line;
switch (type)
{
case QtDebugMsg: out << " DBG "; break;
case QtWarningMsg: out << " WRN "; break;
case QtCriticalMsg: out << " CRT "; break;
case QtFatalMsg: out << " FTL "; break;
}
out << " " << msg << '\n';
out.flush();
}
And then in the function main I put
qInstallMessageHandler(myLogger);
In the new project I get the following errors:
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: warning: C4003: not enough actual parameters for macro 'min'
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: error: C2589: '(' : illegal token on right side of '::'
C:\Qt\Qt5.3.1\5.3\msvc2010_opengl\include\QtCore\q datetime.h:122: error: C2059: syntax error : '::'
The main difference between the two projects is that the one that works is a console application and uses QCoreApplication. The one that doesn't work is a widgets application and uses QApplication.
What do I need to do to get this code in the QWidgets application to work?