Class QSqlError has no member nativeErrorCode() - c++

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.

Related

Wrong path for Qt mkspecs when generating Makefile for VTK under Windows 10

My current task is to set up a working environment for an application using (static) Qt and VTK, under Windows 10.
I successfully installed the Qt 5.11.1 static and now want to build VTK. Any version of VTK does, as long as it is compatible to Qt 5.11.1, and the Qt Modules (VTK_Group_Qt) have to be build. For my version, I decided on VTK 8.1.1, but as said, any version would do.
I used the CMake GUI to configure VTK, using MinGW Makefiles (I use a MinGW64), which worked. Then I wanted to proceed generating the Makefile, having turned on VTK_Group_Qt. The paths and version of Qt were already correctly recognized:
Qt5Core_DIR       C:/build_environment/qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5Core
Qt5Gui_DIR          C:/build_environment/qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5Gui
Qt5Widgets_DIR C:/build_environment/qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5Widgets
Qt5_DIR               C:/build_environment/qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5
Made sure that all of those exist. After that, I hit Generate and got the following error:
The imported target "Qt5::Core" references the file
    "C:/build_environment/qt-everywhere-src-5.11.1/qtbase/.../qt-everywhere-src-5.11.1/qtbase//mkspecs/win32-g++"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
    "C:/build_environment/qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5Core/qt5CoreConfigExtras.cmake"
but not all the files it references
Now, we see that it goes one folder upwards from qtbase and then into the very folder it currently is in, which of course is not a legitimate path. That is, for some reason it tries to go up and then down again, but not with the right amount of folders.
I could try to move the contents of my Qt installation so that the path would be legitimate, but I'd consider that to be pretty much of a smell. Fiddling around in a folder structure that should be correct is not what I understand to be a good solution. I'd rather be willed to change one of the .cmake files of Qt, but that would also be more of a makeshift approach than a real solution as far as I am concerned.
One thing I tried so far was to look at all the CMake variables (checking Advanced in the CMake GUI) in order to see if everything appear to be in order, and especially to see if that faulty path to mkspecs is to be found somewhere there. Found nothing of particular interest.
Does anybody have an idea what went wrong? Tell me if additional information is required. In parallel, I will try to build other versions of VTK, but I'm not too confident that this will solve the issue.
I found a solution which I want to present here, but I consider it a makeshift approach rather than an actual solution, and I hope to see a better answer.
I went to qt-everywhere-src-5.11.1/qtbase/lib/cmake/Qt5Core/ and changed the file Qt5CoreConfigExtrasMkspecDir.cmake (after making a copy).
The original file contains a single line
set(_qt5_corelib_extra_includes "${_qt5Core_install_prefix}/.../qt-everywhere-src-5.11.1/qtbase//mkspecs/win32-g++")
which leads to the faulty path. I changed it to
set(_qt5_corelib_extra_includes "${_qt5Core_install_prefix}/mkspecs/win32-g++")
And it now works fine. Still, I don't feel good about having to change a file of Qt, since I consider the answer the question "Is this famous library at fault?" to be "Most likely I used it wrong."
A possible explanation would be that I used the wrong install prefix when configuring Qt, but shouldn't I be allowed to put any valid writeable path in there? Plus, the prefix is still in the cmake file and thus has some validity.
While this is an answer since it fixed the problem, I'd really like to read comments about what could have originally went wrong.

Problems to compile source code with wxWidgets (MinGW mode) on Windows 10

I am having serious problems to compile a code in Windows (regard3d at http://www.regard3d.org). I have read so many post (two days blocked on this problem) here at stackoverflow and other sites, but without success.
The problem is that it needs wxWidgets. For that I am using MinGW. I have VS Community (the latest version). I run my CMakeLists.txt and everytime I get the message
Could NOT find wxWidgets (missing: wxwidgets_LIBRARIES wxwidgets_INCLUDE_DIRS)
I included the wxWidgets installation directory (which is C:\wxWidgets-3.1.0) in PATH variable (I restarted to it takes effect) and created the variable WXWIN (that also contains the installation directory).
The question: What can I do to solve it?
I think the problem is not building the wxWidgets, but make it be found my cmake. As mentioned, I built it using MinGW, thus I have the folder C:\wxWidgets-3.1.0\lib\gcc_dll and the folder C:\wxWidgets-3.1.0\include which contains two more folders named wx and msvc. I am using the following settings before call the cmake:
set wxWidgets_ROOT_DIR=C:\wxWidgets-3.1.0
set R3D_ALT_wxWidgets_INCLUDE_DIRS=include
set R3D_ALT_wxWidgets_LIBRARIES=lib\gcc_dll
set wxWidgets_CONFIG_EXECUTABLE=build\msw
I'm not very familiar with wxWidgets (so this should probably be a comment, but I can't comment because reasons......), but a quick hack that should work is just throwing the path to the library in LD_LIBRARY_PATH or including it by adding
CPPFLAGS += -L C:\wxWidgets-3.1.0\lib\gcc_dll -I C:\wxWidgets-3.1.0\include
to your makefile.
Failing that, you could explicitly set the environmental variables it's complaining about outside of the makefile.
Again, sorry, this should be a comment. It's not... If someone wants to copy it to a comment and delete this, that'd be grand.
Thank all of you. Solved! Yesterday I compiled both with MinGW and VS and settled the wxWidgets-3.1.0_INCLUDE_DIRS and it worked!

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.

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.

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.