Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Implement MongoDB with Qt: mongocxx

Implement MongoDB with Qt: mongocxx

Scheduled Pinned Locked Moved Solved General and Desktop
c++linuxarch linuxmongodb
12 Posts 4 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arush Gupta
    wrote on last edited by
    #1

    Hi,
    I want to implement mongoDB with qt. I could not find a module for mongodb in qt so I went with: http://mongocxx.org/mongocxx-v3/installation/
    I installed it and tested it with the command (on test.cpp provided in the link):

    c++ test.cpp -o test $(pkg-config --cflags --libs libmongocxx)
    

    and

    g++ test.cpp -o test -I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx
    

    It compiled and ran successfully.
    To add this to qt I found this https://forum.qt.io/topic/77841/qt-and-mongocxx-linker-error but using the solution there did not work for me.
    Here is my .pro file (relevent part):

    #-I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/bsoncxx/v_noabi -L/usr/local/lib -lmongocxx -lbsoncxx
    # ^ ouput of: pkg-config --cflags --libs libmongocxx
    INCLUDEPATH += \
        -I/usr/local/include/mongocxx/v_noabi \
        -I/usr/local/include/bsoncxx/v_noabi
    
    LIBS += \
        -L/usr/local/lib \
        -lmongocxx \
        -lbsoncxx
    

    I am using arch linux if that makes a difference.
    What am I missing here?
    Thanks,
    Arush

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      What error are you getting exactly ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arush Gupta
        wrote on last edited by
        #3

        Hi,
        I get file not found errors on these lines:

        #include <bsoncxx/json.hpp>
        #include <mongocxx/client.hpp>
        #include <mongocxx/stdx.hpp>
        #include <mongocxx/uri.hpp>
        #include <mongocxx/instance.hpp>
        

        Thanks

        JonBJ 1 Reply Last reply
        0
        • A Arush Gupta

          Hi,
          I get file not found errors on these lines:

          #include <bsoncxx/json.hpp>
          #include <mongocxx/client.hpp>
          #include <mongocxx/stdx.hpp>
          #include <mongocxx/uri.hpp>
          #include <mongocxx/instance.hpp>
          

          Thanks

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Arush-Gupta
          This is not my area, so may not be correct, but while you wait for an expert to comment....

              -I/usr/local/include/mongocxx/v_noabi \
              -I/usr/local/include/bsoncxx/v_noabi
          

          This tells compiler to look in those two directories for files. But your includes read #include <mongocxx/instance.hpp> etc. So to find those paths it needs (presumably) to look down from /usr/local/include to find /usr/local/include/mongocxx/instance.hpp (assuming that is correct). In which case, if compiler does not already look automatically in /usr/local/include (I don't know if it does) you would need -I/usr/local/include?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Arush Gupta
            wrote on last edited by
            #5

            Hi,
            Thanks for the response
            But that does not fix it :(
            .pro:

            INCLUDEPATH += \
                -I/usr/local/include/
            
            LIBS += \
                -L/usr/local/lib \
                -lmongocxx \
                -lbsoncxx
            

            Thanks

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Where are the files you include located on your hard drive exactly ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Arush Gupta
                wrote on last edited by
                #7

                Hi,
                /usr/local/include/mongocxx/v_noabi/ contains folder mongocxx and /usr/local/include/bsoncxx/v_noabi/ contains folder bsoncxx.
                Thanks

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I see your issue now. Go back to the original paths you were using but remove the -I before the path, they are unneeded with the INCLUDEPATH variable.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Arush Gupta
                    wrote on last edited by
                    #9

                    Hi,
                    Thanks it worked, I was able to import it, but another issue poped up:

                    error: 'bsoncxx::v_noabi::builder::stream' has not been declared
                       20 | using bsoncxx::builder::stream::close_array;
                          |                         ^~~~~~
                    

                    But I can see folder stream inside builder inside bsoncxx.
                    In the error I see that it want's to import bsoncxx::v_noabi::builder::stream but I want it to use bsoncxx::v_noabi::bsoncxx::builder::stream
                    Thanks

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      That I do not know.

                      Can you provide a minimal example that triggers this error ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Arush Gupta
                        wrote on last edited by
                        #11

                        Sorry for the late response,
                        I solved the issue by reinstalling the packages
                        Thanks for the help.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          shadow_78
                          wrote on last edited by
                          #12

                          Hi, what did you make different for this reinstallation?

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved