Force Qt Creator to use a syntax highlighting for a file



  • Hey guys,

    In my project I use some "non-standard" file extension, like ".ccp", in which the code is C++.

    Problem is: when editing them in QtCreator, I don't get the syntax highlighting, which forces me to use an editor that gives the choice for syntax highlighting.

    Do you know if I can force an opened file to be interpreted in C++ (or whatever syntax I choose to use)?

    I tried some manipulations with kate syntax highlight, but it doesn't seem to work.

    Any idea?


  • Moderators

    Hi xgbi
    which version of qtcreator did you use? A new version 2.2 was just released. It has some added high-lighting features, but those seem to be limited special new features.
    "qt creator release note":http://labs.qt.nokia.com/2011/05/06/qt-creator-2-2-released/


  • Moderators

    ... and you can finally configure MIME types in Qt Creator 2.2, too. So go to Tools->Options->Environment->MIME Types and add your extensions as needed and Qt Creator will treat those just like the built-in ones.



  • That did the trick!

    Thanks!


  • Moderators

    Thanks for the hint Tobias. That is exactly what I was looking for.



  • I tried changing the filter for syntax highlighting for text/x-csrc to match .cl files as well. These are files containing OpenCL code, which look similar to C code but still differs a bit in syntax, hence I will get a lot of underlined code as well. Is there some way to prevent the editor to underline text in red, only for .cl files?


  • Moderators

    Nice: Please do not necro-post and open a new thread for your issue.

    Go to Tools->Options->Text Editor->Generic Highlighter and download more highlight definitions. There is one for OpenCL in the list which should get you basic highlighting, even though there is of course no code model support for that.

    I usually just grab the complete set of highlighter definitions:-)



  • Thanks, it worked! Although it didn't work the first time when I pressed OK (I still got a message saying that no syntax highlighting was found for the file type), and I had to open up the options again and press Apply.

    Why is it not good to ask a question in an already existing post? I figured that if anyone else has the same question as I, they will probably find this thread too when googling for an answer, and now they will find the answer in this post instead of also having to open a new thread...


  • Lifetime Qt Champion

    Hi,

    It's because of time: the original post is 3 years old and you're question is related but not the same so it deserves its own thread :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.