コード例 #1
0
void ub_message_output(QtMsgType type, const char *msg) {
    // We must temporarily remove the handler to avoid the infinite recursion of
    // ub_message_output -> qt_message_output -> ub_message_output -> qt_message_output ...
    QtMsgHandler previousHandler = qInstallMsgHandler(0);

#if defined(QT_NO_DEBUG)
    // Suppress qDebug output in release builds
    if (type != QtDebugMsg)
    {
        qt_message_output(type, msg);
    }

#else
    // Default output in debug builds
    qt_message_output(type, msg);
#endif

    if (UBApplication::app() && UBApplication::app()->isVerbose()) {
        QString logFileNamePath = UBSettings::userDataDirectory() + "/log/"+ qApp->applicationName() + ".log";
        QFile logFile(logFileNamePath);

        if (logFile.exists() && logFile.size() > 10000000)
            logFile.remove();

        if (logFile.open(QIODevice::Append | QIODevice::Text)) {
            QTextStream out(&logFile);
            out << QDateTime::currentDateTime().toString(Qt::ISODate)
                << "      " << msg << "\n";
            logFile.close();
        }
    }

    qInstallMsgHandler(previousHandler);
}
コード例 #2
0
ファイル: QtAV_Global.cpp プロジェクト: aichunyu/QtAV
static void qtav_ffmpeg_log_callback(void* , int level,const char* fmt, va_list vl)
{
    QString qmsg = "{FFmpeg} " + QString().vsprintf(fmt, vl);
    qmsg = qmsg.trimmed();
    QtMsgType mt = QtDebugMsg;
    if (level == AV_LOG_WARNING || level == AV_LOG_ERROR)
        mt = QtWarningMsg;
    else if (level == AV_LOG_FATAL)
        mt = QtCriticalMsg;
    else if (level == AV_LOG_PANIC)
        mt = QtFatalMsg;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    QMessageLogContext ctx;
    qt_message_output(mt, ctx, qmsg);
#else
    qt_message_output(mt, qPrintable(qmsg));
#endif //QT_VERSION
}
コード例 #3
0
ファイル: qdesigner.cpp プロジェクト: muromec/qtopia-ezx
static void designerMessageHandler(QtMsgType type, const char *msg)
{
    // Only Designer warnings are displayed as box
    QDesigner *designerApp = qDesigner;
    if (type != QtWarningMsg || !designerApp || qstrncmp(designerWarningPrefix, msg, qstrlen(designerWarningPrefix))) {
        qInstallMsgHandler(0);
        qt_message_output(type, msg);
        qInstallMsgHandler (designerMessageHandler);
        return;
    }
    designerApp->showErrorMessage(msg);
}
コード例 #4
0
ファイル: qdesigner.cpp プロジェクト: muromec/qtopia-ezx
void QDesigner::showErrorMessage(const char *message)
{
    // strip the prefix
    const QString qMessage = QString::fromUtf8(message + qstrlen(designerWarningPrefix));
    // If there is no main window yet, just store the message.
    // The QErrorMessage would otherwise be hidden by the main window.
    if (m_mainWindow) {
        showErrorMessageBox(qMessage);
    } else {
        qInstallMsgHandler(0);
        qt_message_output(QtWarningMsg, message); // just in case we crash
        qInstallMsgHandler (designerMessageHandler);
        m_initializationErrors += qMessage;
        m_initializationErrors += QLatin1Char('\n');
    }
}