한국어
Qt
 

메시지 핸들러는 디버그 메시지, 경고, 치명적인 오류 메시지를 한곳에 모아 출력하게하는 기능이다. 자신의 메시지 처리기를(C++표준 출력이나 기타 디버거로 출력하도록) 구현하면 응용프로그램 전체 디버그 출력을 완벽하게 제어 할 수 있다. 이것은 로그메세지 출력을 파일 또는 다른 서브시스템으로 리다이렉션(Redirection) 할 수 있음을 의미한다.

 

다음은 예제 소스코드이다. (Qml의 디버스 메세지도 이곳에서 출력된다.)

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

void logOutputHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
    case QtDebugMsg:
        fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtInfoMsg:
        fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtWarningMsg:
        fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtCriticalMsg:
        fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        break;
    case QtFatalMsg:
        fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        abort();
    }
    fflush(stderr);
}

int main(int argc, char *argv[])
{
    qInstallMessageHandler(logOutputHandler); // 메세지 핸들러 등록

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

 

번호 제목 글쓴이 날짜 조회 수
공지 Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서 운영자 2019.01.05 87655
139 클라우드용 Qt file makersweb 2024.01.16 947
138 QML에서 Websocket 서버와 통신 file makersweb 2021.09.18 961
137 Qt로 작성된 안드로이드 APP에 Splash Screen을 추가 file makersweb 2020.03.10 974
136 Qt 응용프로그램에서 Lottie Animation사용 file makersweb 2021.05.30 983
135 QML 에서 QR코드 생성 file makersweb 2021.08.20 987
134 Qt로 작성된 iOS 앱에서 시리얼 통신 file makersweb 2022.04.30 993
133 Qt 5.15 및 Qt 6의 출시 일정 makersweb 2020.04.09 1019
132 Qt 5 코드를 Qt 6로 포팅하기 위해 도움이 되는 Clazy Framework file makersweb 2021.03.01 1029
131 QML 바인딩 끊김 진단 makersweb 2020.11.08 1033
130 [Qt] Google Play의 향후 요구 사항을 준수하는 방법 [2] j2doll 2019.07.29 1042
129 Qt기반의 서버와 클라이언트간 SOAP(Simple Object Access Protocol) file makersweb 2020.05.11 1044
128 Qt 6.0의 개발 호스트 및 대상 플랫폼 makersweb 2020.09.16 1051
127 Qt로 XML 파싱 : Qt 6에서 업데이트된 (Parsing XML with Qt: Updates for Qt 6) [1] j2doll 2020.01.16 1070
126 QML에서 D-Bus 통신 file makersweb 2023.03.15 1071
125 Qt MQTT 에 대해서 file makersweb 2020.06.02 1087
124 Qt 6에서 QList 변경사항 makersweb 2020.10.08 1098
123 QScopedPointer 소개 및 사용법 makersweb 2019.11.29 1136
122 QML 전역 객체 (Global Object) file makersweb 2019.04.10 1153
121 QOpenGLWidget 을 투명하게 적용 file makersweb 2020.02.05 1169
120 ShaderEffect QML Type을 이용한 버튼 클릭 효과 file makersweb 2020.05.22 1174