Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Creator c++11 syntax highlighting for generic projects

My core question is, when using Qt Creator as a code editor for "generic" (non-Qt) projects, how do I tell it to use c++11 syntax highlighting?

I have a c++11 project I've been working on for awhile, and I decided I'd give Qt Creator a try. This is a plain vanilla c++ project, with a hand-coded makefile and so forth.

Qt Creator opened up the project ("eSLIME") just fine, and created three files: eSLIME.config, eSLIME.includes and eSLIME.files. It did not create a .pro file.

It seems not to recognize c++11 calls. For example, it underlines "#include <unordered_set>" in green, and indicates that there is no such file or directory.

I suspect I'm supposed to put something in the .config file, but I can't figure out what and google searches aren't helping. I tried appending -std=c++0x, which didn't work.

PS: The code is too broken to build right now, which is why I was switching to an IDE.

like image 453
David Bruce Borenstein Avatar asked Jun 04 '13 17:06

David Bruce Borenstein


2 Answers

2 years passed from this question and answers, but nothing changed in Qt Creator (at least for linux): even newest version (now it's 3.5) can't parse C++11 headers.

The problem is that by default __cplusplus in internal Qt Creator parser is defined to some value less than 201103L, there are a lot of checks of this macro in STL headers, something like this:

#if __cplusplus < 201103L
#include <bits/c++0x_warning.h>
// disable all tasty functionality
#endif

Firstly I tried adding to *.config the following line:

#define __cplusplus 201103L

Nothing happened.

After some investigations I finally found proper solution: just write in *.config:

#define __cplusplus 201103

Magically everything becames alive!

like image 153
avtomaton Avatar answered Sep 22 '22 13:09

avtomaton


Qt 5.0.2 support c++11 syntax for any c++ file then

just download QT 5.0.2 ( Qt Creator 2.7.0 included).

like image 25
Meysam Hit Avatar answered Sep 21 '22 13:09

Meysam Hit