Qt World Summit: Submit your Presentation

[Solved] QMessageLogContext does not name a type with Qt SDK 5.0.2 - Ubuntu

  • Hi Guys,

    Sorry for the long post, I think the question is relatively simple, but I feel the need to explain the situation I got myself into, however you can probably jump straight to the "Questions" section at the end :) ...

    I have been using Qt SDK 5.0.2 on Windows and Linux with much success :)

    However, I am now expanding my operation and trying to make a sound build environment and a repeatable process to make it. I have almost got there but I have a couple of little niggles left.

    Problem Description
    Using virtual box to keep testing my installations I am creating systems with Ubuntu 12.04 + all updates. This was my process:

    1. install QtCreator from the Ubuntu software centre (this was a mistake I think)
    2. Uninstall Qt Creator from the Ubuntu software centre.
    3. Download Qt SDK 5.0.2 from "qt-project.org/downloads", then cd to the download directory and do:
      @sudo chmod +x qt-linux-opensource-5.0.2-x86-offline.run
      sudo ./qt-linux-opensource-5.0.2-x86-offline.run@

    Other then installing Qt Creator and un-installing it, everything is the same as my working Linux version (on real PC, i.e. non-Virtual box)

    But I get the following issue:
    @main.cpp:60:45: error: 'QMessageLogContext' does not name a type
    main.cpp:60:65: error: ISO C++ forbids declaration of 'context' with no type [-fpermissive]
    main.cpp: In function 'void qDebugMsgHandler(QtMsgType, const int&, const QString&)':@

    Here is my code (which works very well on my Qt 5.0.2 on windows and my other linux installation:
    @// Message handler for qDebug(), qWarning(), qCritical(), qFatal().
    // Note: For qDebug() there are no automatic end-of-lines for maximum
    // flexibility this means that you need to put a "\n" or << endl; at
    // the end of your message.

    void qDebugMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
    case QtDebugMsg:
    myprintf(OUT_ALL, "%s", localMsg.constData());
    case QtWarningMsg:
    myprintf(OUT_ALL, "\nWarning: %s \t%s (line %u) in %s\n\n", localMsg.constData(), context.file, context.line, context.function);
    case QtCriticalMsg:
    myprintf(OUT_ALL, "\nCritical: %s \t%s (line %u) in %s\n\n", localMsg.constData(), context.file, context.line, context.function);
    case QtFatalMsg:
    myprintf(OUT_ALL, "\nFatal: %s \t%s (line %u) in %s\n\n", localMsg.constData(), context.file, context.line, context.function);


    1. QMessageLogContext is a Qt 5 addition. It looks like I don't have that library. When I add the line '#include <QMessageLogContext>', the tool tip even says "can't find file". So how do I install this library?

    2. Also my include paths during the build are suspect, for example:
      @g++ -c -pipe -Wall -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtXml -I/usr/include/qt4 -Icommsnet -Icommsnet/device -Icommsnet/vocoder -Iconfig -Iif -Irpe -Irtp -ItacChat -Iutils -I../_out -o ../_out/main.o main.cpp@
      You can see there are not Qt5 paths whereas on my other linux build there are many more paths like "usr/share/Qt5.0.2/5.0.2/gcc/include/QtCore, etc.... does this mean that I don't have Qt 5 properly installed?

    3. What can I do about this to update it?

    I have the feeling when I installed Qt Creator on its own I screwed up :( , but I am not sure if that is the issue or not

    EDIT: forgot to add: When I remove this code (i.e. comment it out) my project builds and runs great :). I figure that most of the stuff I use is pre Qt5 stuff .. so at least I have some sort of working version of Qt :o

  • [deleted]

  • Lifetime Qt Champion


    It seems you are using a Qt 4 qmake which probably is the one installed with your system's Qt development package.

    Did you take a look into your QtCreator Qt versions ?

  • This is from the "about" in my Qt Creator GUI:

    @Qt Creator 2.7.0
    Based on Qt 5.0.2 (32 bit)

    Built on Apr 9 2013 at 09:31:06

    From revision b6257ef735

    Copyright 2008-2013 Digia Plc. All rights reserved.


    Is that what you mean?
    Is there another place I can see the versions?

  • Lifetime Qt Champion

    No it's not, the version of Qt used to build QtCreator and the one you use to build your application are not related.

    Go to Options/Preferences -> Build & Run -> Qt Versions

  • Ahh.... I see... this makes sense now!, here is what it says:

    Auto Detect:
    Qt 5.0.2 GCC 32bit /opt/Qt5.0.2/5.0.2/gcc/bin/qmake

    Qt 4.8.1 in PATH (System) /usr/bin/qmake-qt4

    I think you are right, so what do I need to change to make that Qt5?, just point it to the Qt5 path? (where would that be?)

  • But... I just looked at my working Linux and that is exactly the same :(, except it has a different "manual" version 4.6.2...

  • Lifetime Qt Champion

    Go in the Kits tab and either add a new kit using your Qt 5 or change the current kit to use your Qt 5

  • Right... so, I have no idea exactly what happened, but this has fixed my issue! :)

    What I did was:
    Attempted to "Add..." and kit in the build and run menu. Saw loads of options that I did not understand. Then cancelled it. Went back in and saw a new "Desktop" entry under "Manual:". I clicked on new entry again, click auto-detect a few times... Then finally I deleted my new entry.

    After that I could not build my project (option was greyed out).

    Then I closed and opened Qt Creator and tried again, it came up with the "you need to configure your project" page (like when you get the project with no .pro.user file). I had two options, I check the one that had 5.0.2 in it and un-checked the other.

    Then... it all just works! - I have the same kits and versions in my build & run options...
    I guess this allowed Qt to update itself or something?

    Anyway, here is my build output:
    @g++ -c -pipe -Wall -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_XML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/opt/Qt5.0.2/5.0.2/gcc/mkspecs/linux-g++ -I. -Icommsnet -Icommsnet/device -Icommsnet/vocoder -Iconfig -Iif -Irpe -Irtp -ItacChat -Iutils -I/opt/Qt5.0.2/5.0.2/gcc/include -I/opt/Qt5.0.2/5.0.2/gcc/include/QtXml -I/opt/Qt5.0.2/5.0.2/gcc/include/QtNetwork -I/opt/Qt5.0.2/5.0.2/gcc/include/QtCore -I../_out -o ../_out/main.o main.cpp

    Thanks very much for your help SGaist :)

  • Lifetime Qt Champion

    Great !

    You're welcome !

    Don't forget to update the thread's title to solved so other forum users may know that a solution has been found :)

  • Ahhh.... I never knew how that happened!, I thought it was an admin guy doing that :o

    I will update it now.

Log in to reply