QT Creator, syntax checking for c++11

前端 未结 4 1684
时光说笑
时光说笑 2021-01-12 06:17

How to turn off error highlighting (red wave under the code) for c++11 cycle range-based operators like that?

int myint[] = {1,2,3,4,5};
for (auto x : myint         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 06:58

    There is "syntax highlighting" (coloring) and there is "syntax checking" (wavy underlines). The syntax coloring does seem to be related to Kate as @Koying suggests, you can modify the colors and turn it off. As of Qt Creator 2.5.0 it doesn't seem to have a problem with most C++11 examples I paste off the web, although your example does indeed still have the underline:

    http://labs.qt.nokia.com/2012/05/09/qt-creator-2-5-0-released/

    Also unfortunately, at the time of writing (June 13th 2012, which is about a month after the release) the latest integrated SDK package is still installing Qt Creator 2.4.1 by default. :-/

    If this is the boat someone is in and wants to try the latest, don't do what I did by wiping out your Qt SDK install using /opt/QtSDK/SDKMaintenanceTool! That wasted time on a reinstall, after which I executed a sudo rm -r /opt/QtSDK/QtCreator, then told the new Qt Creator release to install to /opt/QtSDK/QtCreator. I'll update this post if I hit a snag with that choice!

    http://qt-project.org/wiki/Qt_Creator_Releases

    BUT though it seems to work with many C++11 constructs it does nothing for your example nor the particular case I tripped across, which is the unspaced> for templates.

    (Note: It may seem like a minor thing, but it's a big C++11 feature for me. I hate dealing with having to do tailspaced >...which led me to always do fullyspaced< nested< syntax > > on all templates to keep things consistent. Even simple cases like vector< int >. Now that they fixed the compiler, I'm ready to kill all of that whitespace noise.)

    There doesn't seem to be any way to turn off the wavy underlines (unless you recompile Qt Creator??).

    in qt-creator-2.5.0-src\src\plugins\cpptools\cppmodelmanager.cpp:
    
            QTextCharFormat errorFormat;
            /* disable error underline
            errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
            errorFormat.setUnderlineColor(Qt::red);
            */
    
            // set up the format for the warnings.
            QTextCharFormat warningFormat;
            /* disable warning underline
            warningFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
            warningFormat.setUnderlineColor(Qt::darkYellow);
            */
    

    Either way, it's an insane consequence of duplicating the work of the compiler in the IDE instead of having the two share front-end code. We live in the dark ages of software. Won't someone save us? [/rant]

    Here's some of the relevant code (I think):

    https://qt.gitorious.org/qt-creator/qt-creator/blobs/master/src/plugins/cppeditor/cpphighlighter.cpp

    ...and the lexer here, note the member _cxx0xEnabled:

    https://qt.gitorious.org/qt-creator/qt-creator/blobs/master/src/libs/cplusplus/SimpleLexer.cpp#line80

    Besides your for syntax, the template spacing is the only thing I've found in C++11 that causes the lines. That's major enough to me that I might just build my own QtCreator to address it!

提交回复
热议问题