Downloading MongoDB Drivers to use in QT
-
Not sure if this is really the place I should be asking this, but from my experience everyone here has been extremely friendly and willing to help.
I looked at many resources, including this QT thread (the following)
My main issue seems to be right now I do not understand, how to download the MongoDB C++ driver. The documentation is not helping me, and I am sure it is useful I just do not understand it... I tried to find some videos online, but nothing I saw was really going over the installation part, which is what I can't figure out, so I assume I am stuck on the simplest of parts.
I was just wondering if anyone has done this before, and would be willing to help me get this up and running.
If this is simple take it easy on me :D. Thanks in advance!
EDIT:
So I have been at this for almost 5 hours...is this what I am supposed to be following?
http://mongoc.org/libmongoc/current/installing.html#preparing-a-build-from-a-release-tarball
- Download the TAR from the github link provided in the
wget
command - Run the tar xzf command on the file
- Run
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
Now a question on number three, is this really necessary? What's the point? I use qmake, within Qt Creator when compiling my apps, so is this necessary?
I have a feeling it is necessary in order to compile the driver so I can use it within Qt so I can use it as a library? I have gotten further than before with having an actual file path with headers and stuff...sorry for asking simple questions
- Download the TAR from the github link provided in the
-
You are missing the
-l
before the lib path.In the absolute your should have something like:
LIBS += -LC:/mongo-c-driver/lib/ -lmongoc-1.0 INCLUDEPATH += C:/mongo-c-driver/include/
As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.
On an unrelated note, you should also consider moving your project management to cmake.
qmake
is now legacy from a Qt point of view and projects are encouraged to use cmake in its place. -
Hi,
On which OS are you ?
In any case, AFAIK, you need libbson to write client applications.There's no Qt driver for NoSQL database so you have to write the client side yourself.
-
Hi,
@SGaist said in Downloading MongoDB Drivers to use in QT:
On which OS are you ?
Windows 10.
@SGaist said in Downloading MongoDB Drivers to use in QT:
There's no Qt driver for NoSQL database so you have to write the client side yourself.
Sorry if this is a silly question, but by writing the client side myself what exactly do you mean? Basically all the operations of insertion, updating, deleting, etc.?
The goal is to have an application connected to a cloud database (SQL or NoSQL). The only reason I chose MongoDB Atlas (the cloud version), is because I have far more experience in mongo vs any other DB, as well I know MongoDB Atlas has free tiers in which I can just use them for project like so, rather than having to purchase a plan for another cloud DB.
-
What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.
You don't have the same option with NoSQL so you will have to write stuff like described in the MongoDB C++ tutorial. That's what I meant by client side.
By the way, I was wrong about libbson, I have mixed it with a different library, sorry.
-
@SGaist said in Downloading MongoDB Drivers to use in QT:
What I meant is that there's no abstraction for NoSQL as there is for SQL. With the Qt SQL module, you basically open the connection and then write your queries.
Okay, thank you for clarifying this.
As for the link you had sent, I have not come across that one yet, surprisingly from all the ones I have been looking at, and I will take a look. Although, with the one I had followed I ran CMake on my TAR downloaded from the link (here), and I got a bunch of Visual Code files. I was a bit confused how this would be used in Qt, or if I was supposed to run a qmake on it or something... I am using MinGw32 for the compiler, maybe I need to switch to MSVC if I were to do this?
-
The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.
Based one the article they seem to use Visual Studio but you can try with MinGW by modifying the tool in their configuration example.
Note that they use cmake as project management tool. I would advise to do the same for your project as qmake is now deprecated. It can still be used for client projects but the Qt framework has switch to cmake for its build system.
-
@SGaist said in Downloading MongoDB Drivers to use in QT:
The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.
Yes, correct.
So I got a little further with some research and following along with the tutorial. Although, I am still a little stuck and was wondering if you can steer me in the right direction, although if you aren't able to I understand as this is not exactly Qt related.
I have this folder path in my C drive (pictured below). In the include folder it has the header files, for both libmongoc-1.0 and libbson-1.0. (so you might have been correct in your previous comment). Then the lib directory has these, pictured below.
I added this into my *.pro file, and it builds fine.
LIBS += C:/mongo-c-driver/lib/mongoc-1.0.lib
Although once I go to use
#include <mongoc/mongoc.h>
I get an error saying the file cannot be found, which makes sense obviously because the file is not in that relative path.If I plan on packaging this application to be used on another desktop, how would I go about including the headers, along with the lib file to be used? I know that including the headers within the code is not the answer, as you had stated below.
@SGaist said in Downloading MongoDB Drivers to use in QT:
The goal is not that you integrate their code into your project but that you build their libraries and then use them in your code.
I will be looking into this in the meantime, and update my comment if I end up figuring this out. I have a feeling it is something simple I am completely overlooking. Thanks again @SGaist.
-
You are missing the
-l
before the lib path.In the absolute your should have something like:
LIBS += -LC:/mongo-c-driver/lib/ -lmongoc-1.0 INCLUDEPATH += C:/mongo-c-driver/include/
As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.
On an unrelated note, you should also consider moving your project management to cmake.
qmake
is now legacy from a Qt point of view and projects are encouraged to use cmake in its place. -
@SGaist said in Downloading MongoDB Drivers to use in QT:
As for distributing your application, you don't need the header files at all. You just have to distribute the libraries if you use the dynamic version.
By dynamic version, I assume you mean using a DLL? I see DLLs within mongo-c-driver/bin, (see below). Would this just be as simple as putting the DLLs into the application path? Or would the header files be needed in this case? I know you said they would not be needed, although just a little confused on how else the function definitions would be referenced in that regard.
@SGaist said in Downloading MongoDB Drivers to use in QT:
On an unrelated note, you should also consider moving your project management to cmake. qmake is now legacy from a Qt point of view and projects are encouraged to use cmake in its place.
As for this, I will definitely start migrating some stuff over. I have been using
qmake
ever since I started programming with Qt, so it will be a bit of a learning curve (again) on how to change everything over, so if you have any good information please let me know! Otherwise Google is my friend!I will definitely be marking this topic as solved once I hear back from you. Unsure if the thread locks when it becomes solved. Thanks again!
Edit:
Also, would using
cmake
overqmake
get rid of the *.pro file configuration? Or is that completely irrelevant? -
The header is only required when you develop your code. At runtime, it doesn't do anything. Your application is linked to the library.
Yes, it's the
.dll
that are required and yes again, you deploy them along with your application executable.Yes, you will use a
CMakeLists.txt
file in place of the.pro
file. There's a small helper script call qmake2cmake that you can use to get your porting effort started. -