QT + CImg will not build on OSX 10.9 - c++

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.

Related

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

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.

Class QSqlError has no member nativeErrorCode()

I have been struggling with this problem for quite a while, and unfortunately neither my own reasoning, nor google search helped me. In simple terms, I am trying to use nativeErrorCode() function with QSqlError class. Compiler says: mainwindow.cpp:43:86: error: ‘class QSqlError’ has no member named ‘nativeErrorCode’. This is the line that it references (to be exact, two lines):
errorCreatingBooksTableMessageBox.setDetailedText((query.lastError().nativeErrorCode().isEmpty()) ?
query.lastError().text() : query.lastError().nativeErrorCode() + "\n" + query.lastError().text());
Problem seems trivial, but I can't find an answer on my own. #include is in mainwindow.h file. After some research, I noticed other people on other forums suggesting that compiler uses wrong version of the header file, which would seem very likely to happen since function nativeErrorCode() was introduced in Qt5. I tried to move qt4 folder to trash, but still, no effect. Any help would be appriciated
I am not sure which OS you encounter this issue. However In most of the Linux OS Image, prebuild with Qt4, Even we build Qt5 libraries additionally, the system environment may use old Qt4 libraries to generate make files. This is very common if we are building Qt5 from source codes. So it would be better you can try to execute qmake from Qt5 path. So the Makefile will be created to build for Qt5 libraries.
In order to confirm, Open the Makefile and check the variable QMAKE is refering to Qt5 or Qt4 libraries.
I am updating this from my system for your reference, "QMAKE = /home/user1/Qt5.6.0/5.6/gcc_64/bin/qmake" From this, It is clear that Makefile is using Qt5 libraries and further compilation, Qt5 libraries will be used to compile my application source code.

Using Qt5 in a library

I have a library that integrates some GTK functionnalities, and I decided to switch to Qt.
So I created a test cmake file to try to integrate Qt5 but it does not work because when I load the libary dynamically using an executable I get "undefined symbols".
undefined symbol: _ZN8UIWindow16staticMetaObjectE
I googled a lot, and it does not seems to be that simple si any kind of help, or comments would be much appreciated.
Here are the relevant files I use.
Ok I found the solution. Since I use different folders for the header and the source files, I have to manually specify where is the file containing the qt code.
QT5_WRAP_CPP( MOCS_HDRS ${INCLUDE_DIR}/UIWindow.h )
The error indicates that the MOC file for your UIWindow class was not generated or built correctly. Qt expects certain meta-information for the class generated by MOC (MetaObject Compiler, IIRC).
Your CMake script turns on automoc which usually works, so I suggest you take a look at the output of CMake to see if it is running that step for your class or not.

PlaySound() In C++ Doesn't Work

I've been trying to figure this out, and I just can't seem to.
When you include window.h at the top, there is supposed to be a PlaySound() function inside of it.
I added window.h but I keep on getting a "PlaySound was not declared in this scope" error.
I tried going into the project's build options and adding "-lwinmm" into the linker settings, but it still doesn't work.
I'm using Code::Blocks.
Anyone have a solution?
You need to #include both windows.h and mmsystem.h, in that order. This is noted in the community section of the documentation.
I assume you are coding on windows and you actually wanted the interface file called "Windows.h". Also make sure you are using the correct namespace, I'm not a windows programmer, but that's a start. I also don't know haw you are loading the file or wether you are using the win32 or .net frameworks. But then from the sounds of it you might not either.
If you're trying to use .net you can start here
http://msdn.microsoft.com/en-us/library/system.media.soundplayer
win 32 start here
http://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx
ah here it is winCE audio API
http://msdn.microsoft.com/en-us/library/aa909766.aspx

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.