MongoDB integration with Qt
-
I did as you suggested to me and I'm including the mongocxx library.
Unfortunatelly I get a
usr/local/include/bsoncxx/v_noabi/bsoncxx/types.hp:39: Parse error at "{"
and I don't know what to do, since a collage of mine working on the same project is not getting this problem (using the exact same code).The error is in correspondence of
enum class type : std::uint8_t { #define BSONCXX_ENUM(name, val) k_##name = val, #include <bsoncxx/enums/type.hpp> #undef BSONCXX_ENUM };
If I remove
type : std::uint8_t
it then complains about other errors...
Any suggestions? -
Hi,
Can you show the code that you are using that triggers that error ?
-
Sorry, but it is confidential and I'm not sure I can share it.
Using#ifndef Q_MOC_RUN
as suggested here https://bugreports.qt.io/browse/QTBUG-80578 makes the compilation error disappears but the program then crashes immediately at runtime. -
In that kind of case, you can also provide a minimal example that shows the issue.
And what does the stack trace of the crash say ?
-
Well, without the code, it doesn't help much.
-
A minimal piece of code to reproduce the error is already available here https://bugreports.qt.io/browse/QTBUG-80578, but it seems to be a bug. Unfortunately, I didn't find any workaround and I'm unable to continue with the project.
-
You wrote that the compilation was successful so that part is fine, isn't it ?
As for the run time crash, what is the stack trace ?
-
Do you have the same issue if you write a minimal test application using only bsoncxx ?
-
@enne9 said in MongoDB integration with Qt:
n mongocxx and my Qt version. I
so, what was the compatible versions?
-
I confirm that I have the very same issue with Qt 5.15.2 and mongo-cxx-driver 3.5.0 (had to add Q_MOC_RUN defines, and then the same crash when building mongocxx::client).
If the author of the thread show up again, which combination of version did you use that worked ? Did you perhaps use the legacy mongo-cxx-driver ? Considering how different the two are, it might work... but the new generation of mongo-cxx-driver is already pretty damn mature, and the legacy one has reached end of life, so it's not really a viable solution on the long term.
EDIT: Alright, the original author wording lacked precision: this has nothing to do with the combined use of Qt and mongo-cxx-driver.
The problem is due to linking to a certain version of the mongo-cxx library, while using the includes for another version.Turns out I had already installed mongocxx elsewhere, and the CMake package files for mongo-cxx-driver seem to have some issue finding the include files on its own, so that issue might happen if you're not careful enough and mess up the include part.
-
Hello,
If you want an easier integration with Qt and MongoDB, you can try QxOrm library.
The documentation can be found here.
And here is a project example on GitHub.Please note that the latest commit on GitHub for QxOrm library supports Qt6.