한국어
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 85857
59 Windows에서 Qt D-Bus를 사용하여 프로세스간 통신(IPC) file makersweb 2019.05.02 4478
58 QML과 QtQuick 모듈 개념과 기본 타입들 makersweb 2019.04.26 13388
57 QML 전역 객체 (Global Object) file makersweb 2019.04.10 1048
56 tslib의 ts_calibrate를 응용해서 Qt로 터치보정기능 구현 file makersweb 2019.04.06 1365
55 GPU가 없는 장치에서 Qt Quick을 사용 makersweb 2019.04.02 1857
54 QTextCodec클래스를 사용하여 유니코드와 EUC-KR 변환 makersweb 2019.03.25 2891
» qInstallMessageHandler를 이용한 디버그 메세지 출력 제어하기 makersweb 2019.02.25 1352
52 Qt5기반 독립 프로세스(out-of-process)로 동작하는 가상키보드(virtual keyboard) file makersweb 2019.02.24 2626
51 Qml 기본 컴포넌트 강좌 (4) - 모델 리스팅(Listing) file 운영자 2019.02.23 5298
50 Qt Bluetooth를 이용한 시리얼(Serial) 통신 file makersweb 2019.02.17 3561
49 Qml 기본 컴포넌트 강좌 (3) - 배치(positioning) 컴포넌트 file 운영자 2019.02.10 4866
48 QString 문자열 다루기 예제 운영자 2019.01.26 40052
47 Qt SQL을 이용한 가벼운 데이터베이스 다루기 [1] file 운영자 2019.01.23 6955
46 구글 클라우드 Speech-To-Text API를 Qt기반(C++, Qml)테스트 [7] file makersweb 2019.01.20 2616
45 QNetworkAccessManager를 통해 HTTP POST 하는 예제 makersweb 2019.01.17 4761
44 Qt응용프로그램 실행 시 콘솔창(터미널)같이 띄우기 file makersweb 2019.01.16 4482
43 안드로이드 가상장치 사용 file makersweb 2019.01.13 1072
42 Qml 기본 컴포넌트 강좌 (2) [2] file makersweb 2019.01.05 8616
41 Qml 기본 컴포넌트 강좌 (1) file makersweb 2019.01.03 12060
40 QtWayland와 ivi-compositor file makersweb 2018.12.27 2403