Qt foreach is giving me sytax error highlight in Eclipse.
I'm programming in C++ using a Qt framework.
I use Eclipse SDK (3.5.2) as my text editor / IDE.
I compile in a console outside of Eclipse using GCC.
When I'm editing my files in Eclipse, I find that Qt's "foreach" is highlighting as a syntax error.
Does anyone know how to fix this? It's not majorly important or anything but it's starting to annoy me. It's as though it's not recognizing the command or something...
If you've enable c++11 support in Eclipse you can redefine 'foreach' to be a range based for loop. In the project properties, select 'Paths and Symbols' in the left pane, then select the 'Symbols' tab. Add a new symbol with 'Name'= foreach(a,b) 'Value'=for(a:b) Select 'Add to all configurations' and 'Add to all languages'
foreach is not a standard C++ keyword. I think the Qt moc compiler transforms this to generated code, like it does with signals/slots in Q_OBJECT tagged classes.
So it's to be expected that Eclipse fails to recognize this.
If you use these Qt-specific features, you're better off using Qt creator.
Related
I installed Microsoft's C++ extension on VSCode, but when I'm writing C++ code,
my screen looks like this.
The autocompletion feature works, but there is no documentation/proper description given to me for any of the built-in C++ functions/classes. Compare the above to what it looks like on an official screenshot of the C++ VSCode extension.
I have my \msys64\mingw64\bin folder added to path too, so there shouldn't be a problem there. Any suggestions on how I can fix the tooltips my IDE gives me for C++?
I´m new at Visual Studio C++ and maybe I´m asking a very trivial question. I have a project/application but I have to add a few new features to it. When I open the project in MVS and in "dialog" folder there are windows (or dialogs?) used by application and I can modify them but I´m not allowed to add components/tools that I really need. I have only Dialog editor tools unlocked. I can compile an run application but When I try to add a form to project I´ll see a message:
You are adding a CLR component to a native project. Your project will be converted to have Common language runtime support.
I´ve googled some information about .NET forms and windows dialogs, but I do not know what to do next. If I choose "yes" (convert project) I cannot compile it anymore.
What can I do if I would like to use a ZedGraph controll to plot graphs from data in this app?
The C# GUI tools are different to the C++ tools (like MFC).
When you try to add C# tools to a C++ project the IDE warns you "You are adding a CLR component..."
Depending on which IDE you are using, when you bring up the resource view (http://msdn.microsoft.com/en-us/library/d4cfawwc.aspx) e.g. with ctrl + shift + E you should be able to find the existing dialogs and double click to edit them.
It seems that ZedGraph is a C# library (from the docs), so you will have to convert into a C# project in order to use it, which will not be straightforward, or use a suitable C++ one.
I want to use qt creator, only as an editor, which does code completion and finds declarations etc. I dont want to use it to build etc. Is there a way, I can circumvent the need of qt-libraries? I am using a server, where my file space is limited. Also, without qt libraries, it does not allow making even a project. When I tried to install qt-libraries, it configures fine, but on make gives error.
So, can you suggest an alternative? Thanks
No, you need the Qt libs because the editor was coded in Qt.
Actually - at least under Windows -, you can. You just have to deselect all Qt library versions and only select the editor. If you want to have a debugger available on Windows, also select the checkbox for CDB support.
I have forgotten how this works with the Linux installer, but I imagine the same applies there as well, except of course for the CDB debugger, which is not available on Linux. Instead you should be able to chose from GDB and some other alternatives, though it might not be during the installation.
Once you installed it and are about to set up a new "Plain C++" project, you can't select a Qt version when creating a new kit, obviously.
If you blindly selected an already existing kit, Qt Creator might have tried to use a Qt installation for your vanilla C++ project. Instead of doing so, you should click the "Manage..." button on one of your preexisting kits and add a new, custom kit. Here you can set the "Qt version" option to "None". The rest should be set according to your needs.
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){/**/}
Hover prompt shows "unexpected token :". The code compiles perfectly.
Another issue - the autocomplete doesn't show unique_ptr in std:: namespace, though compiles OK.
Qt Creator 2.4.0 Based on Qt 4.7.4 (32 bit) Built on Dec 12 2011 at
01:10:32
I don't understand the line of reasoning in Andrew's answer. Why would customizing syntax checking make sense? The syntax is either correct given the context set by the compiler command line, or it is wrong. If it is wrong, it should be marked as such, if not, not. If correct code is marked as wrong, it is a bug, or at least unsupported feature, in the IDE, and it needs a fix, not "customization".
Having said that, the cited example
int myint[] = {1,2,3,4,5};
for (auto x : myint){/**/}
works fine here (fairly recent build from master branch).
Regarding the other comment on Kate: Kate's syntax highlighting is used by Qt Creator as fallback in cases where there is no more specific syntax highlighting available for a file. In the case of C++ (98/03/11) there is a real code model used, not Kate's definitions.
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<nested<syntax>> 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<nested<syntax> >...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!
If you're writing in C++11 you should change from using QT Creator as the IDE to using Eclipse CDT. At least this is how I solved this problem. QT Creator doesn't seem to have any way to customize this real-time syntax checking. Eclipse on the other hand is extensively customizable in this regard.
Update: I think that QtCreator has improved its support for newer versions of C++ since this answer was given, so it is no longer correct. I can't delete it as it is an accepted answer.
Qt Creator is using the syntax highlighting definitions from the Kate editor (from KDE). See Tools-Options-Text Editor-Generic Highlighter.
If Kate has a definition for c++11, you can use it or you can develop your own.
Using MSVC compiler, you need to add the line:
/std:c++11
To your project's project.cxxflags configuration file, where project must be replaced by the name of your project. This file is located at the root of your project directory, you may have to create it if it does not already exist.
Remark: this setting is a MSVC parameter so the syntax would likely be different for other compilers.
Tested with Qt Creator 4.15.0-rc1 (April 2021) and Visual Studio 2017 on Windows, where the error:
`error: no member named 'optional' in namespace 'std'` when trying to use std::optional from header <optional>
disappear when adding /std:c++17 (std::optional was added in C++17).
I'm using an uncommon C compiler with Eclipse CDT. I have a make file setup which is nice, but I'd like IDE integration with the error / warning output of my compiler.
Does anybody know what steps I can take to write a plugin for parsing / supporting my compilers output? I think it should be easy but there is a barrier of entry of figuring out where to start. Would be nice if Eclipse would let me do New -> Compiler Error Parser Plugin, or something like that.
Thanks
It's not quite that simple...
First of all make sure you have the Eclipse PDE (Plug-in Development Environment) and CDT SDK installed. If not then you'll need to tell Eclipse to download them (Help -> Install New Software).
Then, create a new Plug-In project. In its Extensions tab, add a new extension against point org.eclipse.cdt.core.ErrorParser. You will then have to write some java code to actually implement it. Fortunately the PDE makes the meta-work relatively straightforward; you put the name of your class in the appropriate box and click on the "class*" hyperlink and it will offer to create a skeleton class for you.
I suggest you grab the source code to the CDT and have a look at GCCErrorParser.java as an illustration of the sorts of things yours will have to do.
Finally, when you're ready to test it, set up a debug configuration of type Eclipse Application. (This will spawn a second instance of Eclipse; it has to use a different workbench.) Go into the properties of your C project, Settings panel, Error Parsers tab and switch on your shiny new error parser.
In Eclipse CDT 7.0.1 it's pretty simple. Just add a new error parser
under Window -> Preferences -> C/C++ Build -> Settings
and add regular expression with 3 groups: filename, linenumber and error description.
For example, for Visual Studio compiler regexp will be:
(.*?)\((\d*)\)\s:\s(.*error.*)
$1 - filename
$2 - line number
$3 - error description
IBM has published a step-by-step guide to how you can write your own CDT parser, its available here
Relevant google search for future proofing should be:
https://www.google.com/search?q=ibm+eclipse+write+cdt+parser&oq=ibm+eclipse+write+cdt+error+parser
In CDT 7 there is going to be a regular expression error parser included which should make this sort of thing much simpler. There are some details on the faq.
CDT 7.0 won't be released until the end of June, but you could try milestone builds to see if it does what you want. These can be downloaded here. You'll need to have a matching milestone version of the eclipse platform too.
I am using this plugin:
http://www.isystem.com/downloads/downloads/204-Eclipse-Downloads.html
is this working ?
(.*)\((\d+)\)\s:\sError(.*)
file: $1
line: $2
desc: $3
.
srkos
In CDT 8 this functionality does not require a plugin. I have support for several compilers and build systems using simple regular expressions. See screenshot here. You can test the regexes directly in the console output before copying them to this dialog. If you need to move them between machines, the resulting parsers are stored in your workspace under .metadata/.plugins/org.eclipse.cdt.core