Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

New user - Qt5 Creator IDE displaying 'errors' although compiles ok



  • Hi - I've just installed Qt5 Creator in my Ubuntu 20.04 LTS system, and trying to get something, anything, to build. It's very frustrating; I was expecting this to be easy.

    For example, if I open the Analog Clock example project, it says I need to copy it into a writable location to be able to compile it. No problem - I choose a directory under my /home/user directory.

    The project opens in the main.cpp, and the 2nd #include, of "rasterwindow.h", is underlined in red with a "file not found" error on the right hand side. I'm pretty new to Qt but I suspect the problem is in the .pro file, which has:

    include(../rasterwindow/rasterwindow.pri)
    

    That rasterwindow directory doesn't exist where the project has been copied to. So I create a symbolic link to where it does exist. And if I close the project and re-open it, the #include "rasterwindow.h" is no longer underlined. But on the next line:

    class AnalogClockWindow : public RasterWindow
    

    the RasterWindow is underlined in red, with the error "expected class name".

    At this point I give up and try creating my own simple Qt Widgets app. I accept all the defaults, and I'm presented with main.cpp:

    #include "mainwindow.h"
    
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w:
        :
    

    But QApplication has error "variable has incomplete type 'QApplication'", with error "unknown type name 'MainWindow'" below.

    I've obviously got something fundamentally wrong somewhere; please can anyone help?

    Cheers
    John



  • Well, actually I can build things, but not within Qt Creator.

    I can build both the (copy of the) analog clock example, and my own stub app, by running qmake in the project's directory followed by make. No errors, and the executables run fine. (Although I still need to create the local rasterwindow symbolic link for the analog clock.)

    So the problem must presumably be something in my Qt Creator settings.



  • @JohnM64
    Assuming you mean the code compiles fine, but these are warnings you see only when editing in Creator. It is the "code model parser" in the IDE which is showing these errors. Under Ubuntu 20.04 you need to replace the shipped clang version 8 by up-to-date version 9. I think it's sudo apt-get install clang-9, or similar.



  • @JonB thanks, but I've installed clang9 (actually clang --version says it's 10.0.0-4ubuntu1), restarted Qt Creator, and I'm still getting the same 'errors' displayed in the IDE.

    qt.png

    (I've updated the thread title to reflect recent discoveries.)



  • @JohnM64
    That surprises me, because it looks exactly like what I expected for the clang issue....

    Go check the setting, wherever it is in Designer, showing just what clang it is using (for "Code Model", it has a setting page somewhere)? There you can change over to whatever the simpler, non-clang option is temporarily, to verify it's a clang issue?



  • @JonB
    Apologies for the delay; for reasons I won't bore you with I'm now running under Xubuntu.

    Anyway, it looks like the problem is solved. Under Tools / Options / C++ / Code Model / Clang Code Model it said it was enabled because the plugin was loaded. So I went into Help / About Plugins... and unticked the Load tick-boxes for C++ / ClangCodeModel and Code Analyzer / ClangTools. Might not have needed to untick both of them, but I couldn't be bothered to fine tune it.

    Don't know if this will have negative side effects, but everything looks ok so far.

    Thanks for the help.

    Cheers
    John



  • @JohnM64
    Well this hasn't resolved the issue of getting your clang code model working in Creator, it has just switched it off! You will get a different editing aid experience. If you are happy without clang that is OK for you.


Log in to reply