Trying to compile Qt/C++ code in Code Blocks - c++

I am new with QT, so I am not sure how this works. Im trying to compile some C++ code that includes QT code for graphics. I am using the GNU compiler in Code blocks, but whenever I compile it, It gives this error:
fatal error: QGraphicsRectItem: No such file or directory
So how do I fix this? Is there a different compiler I need?
My include statement is:
#include <QGraphicsRectItem>

It is hard to tell from the info you provided. There are several problems that yield this error, not configured the files correctly, there is no such header file, ..., etc. The error is clear though.
Qt is a big library that is why we need qmake to take care of configuring the files, so theoretically speaking, you can generate Makefile and copy-paste the related data to your code-blocks project. As far as I know, qmake supports Visual Studio and Xcode projects but not sure if there is a tool for code-blocks.

Related

Problem using libxml2 with VS Code under Windows (g++)

I'm not new to programming, but pretty new to C++. I successfully loaded some other 3rd party libraries like curl or sqlite, but I'm having a problem with libxml2 (Platform Windows; IDE VS Code; Compiler g++). I downloaded the binary from zlatkovic.com (x86_x64 if it matters).
After including one or two header files and typing a few lines I wanted to see what the result would be and I tried to compile my code. I added the libxml2-2.dll in my vs code task file under the '-g' flag of the compiler, just like I did it with the others. But this time I received the following message:
"path/to/src/libxml/xmlreader.h:16:10: fatal error: libxml/xmlversion.h: No such file or directory"
Like you can see in the message, the header files are in the "libxml" directory and I also checked they exist.
I guess it's something really basic I'm missing out here, but help would be really appreciated, thanks!
I finally got it. I needed the '-I' flag to the directory with the header files. Thanks everyone!

How do I get the compiler to read a downloaded library?

I've downloaded OpenMesh for Linux Ubuntu. I successfuly compiled it following instructions at
https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/OpenMesh-8.0-Documentation/a04067.html
using cmake, then make. The result is a "build" folder containing, among other things, a makefile and .o files. I want to use OpenMesh in QT Creator, so I put an example code found on their website at
https://www.graphics.rwth-aachen.de/media/openmesh_static/Documentations/OpenMesh-8.0-Documentation/a04088.html
basically it just displays a cube using cout and data structures I've downloaded. However, there are compilation errors of type "undefined reference to" everywhere.
Here is an example : "../OpenMesh-8.1/src/OpenMesh/Core/Mesh/ArrayKernel.hh:154: error : undefined reference to `OpenMesh::ArrayKernel::is_valid_handle(OpenMesh::HalfedgeHandle) const'
I think that this could be caused because I didn't tell the compiler somehow where I compiled OpenMesh, because someone else got this error at https://linuxfr.org/forums/programmation-c/posts/openmesh
I don't really get it, though, and I don't know much about the compiling process. I don't know how to import downloaded libraries and run them in QT. Does anyone know a simple way to do this ?
Any help would be really appreciated.
The correct way to do it is to open CmakeLists.txt in qt creator, which organizes everything correctly.

QT + CImg will not build on OSX 10.9

I'm taking over a project where I need to work with QT Creator and CImg, however it won't build on my machine.
/Users/vikkosmi/Qt/5.2.0/clang_64/lib/QtCore.framework/Headers/qvariant.h:132: error: expected '}'
Bool = QMetaType::Bool,
^
This error, and a dozen similar ones, keeps appearing when I build. Its coming from the Qt Core.
Are there things that need to be rewritten when you move from a windows platform to osx using cimg? As far as I know the code should be portable..
I tried to reinstall libraries, install XQuarts, add library and include paths to the project file, but still the same problem :( Thanks in advance for your help!
What are you building? If you're building Qt, then you have some local modifications that broke it - start with fresh sources.
If you're building some code that uses Qt, then the problem is in that code, not in Qt. The smell of this issue is that something has defined a Bool macro that interferes with QVariant's code.
The file where this happens is not qvariant.h. It is some .cpp file of yours - look at the error messages, they will include something like "while compiling yourfile.cpp". In that file, you need to put #include <QVariant> as the very first line. This should fix the problem temporarily.
You should search for Bool in your code and fix the global namespace pollution. Your code is broken, no doubt about it I think.
The X11 library (used by default by CImg) defines Bool.
As you are working with Qt, you probably don't want to use display capabilities of CImg, so I suggest you deactivate it by defining the macro cimg_display=0when compiling.
CImg will not try to include the X11 headers, and it may solve your problem.

(Special case, might related to VC directory setting) fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

I was bothered by the error
fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
for quite a while, I tried my best to search all the relevant cases but couldn't find a good answer for me.
My situation is, I have a simple piece of code with a couple of dependencies to build, after setting up all the include folders, I'm just experiencing this compiler error all the time. Two weird questions I cannot answer,
There is another win32 console project somebody else set up for this project, working! I'm trying to copy all of his settings (the command line options are exactly the same, all env variables are same, and I run two projects on same visual studio), but just have this 1083 error in my own project.
I was playing around with the settings, one time I changed the platform from Active(Win32) to Win32, then suddenly the compiling works, but after that time I couldn't reproduce it any more.
The thing is, I'm guessing VS in my project might go to a wrong directory
C:\Program Files\Microsoft Visual Studio 8\VC\include instead of C:\Program Files (x86)\Microsoft Visual Studio 8\VC\include
not quite sure, and earlier I was trying to compiling using a building script and make files, same error happened because there people didn't update the correct VS directory.
Sorry I couldn't provide the source code here, and it won't be helpful either since it has a couple of levels of dependency. But I hope based on my description some one might give some idea which direction should I go or spend time on.
iostream.h is deprecated, it should be just iostream:
#include <iostream>
See <iostream> vs. <iostream.h> vs. "iostream.h"
In this version of visual studio (and also in any modern C++ IDE) standard library headers are named without any suffices (iostream instead of iostream.h, string instead of string.h, etc)
Also, C library headers are named like cxxx instead of xxx.h, for example, you should include cstdlib instead of stdlib.h
When you say that you ran your project and the other person's (working) project on the "same visual studio", do you mean the same installation or the same version? If they're not on the same installation, then even if the project settings are copied exactly, it could be that the installation settings are different and that that's what's causing the problem. This may be a long shot, but I'll do my best to explain.
I came across your question because I had a slightly similar problem. Even without dependencies, I couldn't get a simple "Hello, World" program to compile. I used iostream without ".h" as many people suggested and still got C1083. Then I realized that when I installed VS, I unchecked one of the basic features, called "Visual C++ Run-Time Libraries". So I modified the installation to include this feature. Afterwards compilation proceeded successfully and the problem was solved. Is it possible that your installation is missing something that the other person has? If you can get your project to work on this other person's installation, then that might help to pinpoint the problem. Hope this helps. Good luck!
Does a simple hello world program that uses <iostream> compile and run fine?
If so, the Visual Studio system settings are fine and there is something probably wrong in either the project settings or the source.
You can eliminate the source by checking to make sure that the code is actually using #include <iostream> as opposed to #include <iostream.h>. Once that is done, make sure your header search paths point to the right place (the same as the default values in your hello world project for a start)

eclipse and boost unit_test_framework failing syntax check using c++

i have the following Problem.
I started to use the boost library version 1.40, for unit testing.
Since some other people working on the project and not all of them are using eclipse, the program has to be compilable with a makefile. So we used cmake to generate one.
The good thing is, the test is building and working perfectly fine.
But the problem is, when using eclipse (created a c++ makefile project), it complains about several syntax errors (in the sourcecode view).
Something like:
BOOST_AUTO_TEST_CASE( my_test )
{ some code }
will be detected as a syntax error by eclipse. It is really annoying having all these error messages in the IDE. Since after the first line nearly every line in the some code block is marked as having syntax errors as well.
So here is what i tried already:
I added `/usr/include/boost/` to the GNU C++ path options. (properties->C/C++ General->Path and Symbols->Path). This works normally for other external libs that are included by FindPkgConfig in the cmake file. So that the auto completion in eclipse can find the correct classes and function names.
Same way included `/usr/include/boost/test/` directly.
Adding `/usr/lib/libboost_unit_test_framework.so.1.40.0` to the Libraries list.
Adding `/usr/lib` to the Library Paths.
So anyone has a hint how to teach eclipse that the syntax of the boost Macros is correct??
Update:
I forgot:
System is Linux and Eclipse Version is 3.6.1, CDT Version is:
Version: 1.0.0.201009141542
Build id: 201009141542
I don't have a solution but maybe a hint.
I had a similar setup and it worked perfectly until...
the only relevant change I remember is that I changed the name of a test suite.
So (probably) after that, the syntax highlighting went crazy.
I tried indexing and refreshing but it didn't help.
I can't even see the macro expansion because the syntax error prevents it from popping up.
My guess is — still — some indexing issue, because it worked before and I didn't change any include paths. It compiles without problems, but it's urinating these yellow syntax error markers all over the document, which is really, really annoying.
However, it's probably not a path issue because it worked for me before.
I just did this myself using Eclipse Helios, and it does indeed work for me...
Shouldnt you add /usr/include and not /usr/include/boost, since boost is part of the include path used in your program?
For example <boost/unit_test.hpp> is simply <unit_test.hpp> if you include the boost folder aswell..
This is what I have added under GNU c++ include directories:
/usr/local/include //this is where I store the boost folder
/usr/include/c++/4.5.2 //This was needed since not even <map>, <vector> etc would resolve in eclipse.
Intellisense and autocompletion for C++ are pretty much impossible to get right in all cases. If the many macros used in Boost.Test confuse Eclipse, then perhaps you should find a cleaner unit test library. I can recommend Catch, which has a cleaner and friendlier syntax, is header-only so it's much easier to set up, and doesn't rely on macros. It is under active development by another SO user.
I had this problem as well (but on a Mac system). Once I added the boost path to GNU C++ path options, I restarted my operating system and Eclipse doesn't tag BOOST_AUTO_TEST_SUITE as an error any more.