2013-03-03 1 views
3

MongoDB를 백 엔드 데이터베이스로 사용하여 Qt GUI 응용 프로그램을 개발하고 싶습니다. 그래서 MongoDB C 드라이버 또는 C++ 드라이버를 사용해야합니다.Qt Creator 용 MongoDB C driver를 사용하는 방법은 무엇입니까?

사실, Windows에서 C++ 드라이버를 만드는 것은 어렵습니다. 내가 "스콘"을 할 때, 그것은 부스트를 찾을 수없고 나는 부스트를 설치했다. 나는 이유를 모른다.

그래서 MongoDB C 드라이버를 선택합니다. 내가 "스콘"을 만들었을 때 잘 돌아가서 네 개의 파일 (bson.lib, bson.dll, mongoc.lib, mongoc.dll)이 생성되었습니다. 그러나 Qt Creator에서 작동하도록이 라이브러리와 DLL을 사용하는 방법을 정확히 알지 못합니다.

답변

2

저는 C 드라이버를 작성하지 않았지만 Qt Creator를 사용하여 C++을 수행하는 중입니다. 프로젝트에 boost 라이브러리를 포함시켜야합니다. - 어쨌든 다운로드 한 MongoDB 클라이언트 C++의 버전은 Boost 1.49 라이브러리 여야합니다. 다운로드하여 라이브러리에 4 개 정도만 넣어도 모든 라이브러리를 빌드하십시오. 다음은 Qt Creator .pro 파일의 관련 코드입니다. C :/MongoDB 폴더의 모든 내용은 MongoDB 소스에서 다운로드하거나 적어도 직접 다운로드 한 scons로 작성했습니다. Qt는 정적 C++ 런타임에 내장 할 때 내가 here 주어졌다 조언을 따라 정적 런타임에 내장되어 비 Qt는 C++ DLL에 드라이버를 래핑하는 것이 가장, 그래서 무례한 행동을하는 것으로 알려져 있음을

INCLUDEPATH += C:/MongoDB/src \ 
C:/MongoDB/src/mongo/client \ 
C:/MongoDB/src/third_party/boost \ 
C:/MongoDB/src/third_party/boost/boost \ 
C:/MongoDB/src/mongo \ 
C:/MongoDB/src/third_party/boost/boost/algorithm \ 
C:/MongoDB/src/third_party/boost/boost/asio \ 
C:/MongoDB/src/third_party/boost/boost/bind \ 
C:/MongoDB/src/third_party/boost/boost/concept \ 
C:/MongoDB/src/third_party/boost/boost/config \ 
C:/MongoDB/src/third_party/boost/boost/container \ 
C:/MongoDB/src/third_party/boost/boost/date_time \ 
C:/MongoDB/src/third_party/boost/boost/detail \ 
C:/MongoDB/src/third_party/boost/boost/exception \ 
C:/MongoDB/src/third_party/boost/boost/filesystem \ 
C:/MongoDB/src/third_party/boost/boost/function \ 
C:/MongoDB/src/third_party/boost/boost/functional \ 
C:/MongoDB/src/third_party/boost/boost/integer \ 
C:/MongoDB/src/third_party/boost/boost/io \ 
C:/MongoDB/src/third_party/boost/boost/iterator \ 
C:/MongoDB/src/third_party/boost/boost/math \ 
C:/MongoDB/src/third_party/boost/boost/move \ 
C:/MongoDB/src/third_party/boost/boost/mpl  \ 
C:/MongoDB/src/third_party/boost/boost/numeric \ 
C:/MongoDB/src/third_party/boost/boost/optional \ 
C:/MongoDB/src/third_party/boost/boost/pending \ 
C:/MongoDB/src/third_party/boost/boost/preprocessor \ 
C:/MongoDB/src/third_party/boost/boost/program_options\ 
C:/MongoDB/src/third_party/boost/boost/random \ 
C:/MongoDB/src/third_party/boost/boost/range \ 
C:/MongoDB/src/third_party/boost/boost/regex \ 
C:/MongoDB/src/third_party/boost/boost/smart_ptr \ 
C:/MongoDB/src/third_party/boost/boost/spirit \ 
C:/MongoDB/src/third_party/boost/boost/system \ 
C:/MongoDB/src/third_party/boost/boost/test  \ 
C:/MongoDB/src/third_party/boost/boost/thread \ 
C:/MongoDB/src/third_party/boost/boost/tuple  \ 
C:/MongoDB/src/third_party/boost/boost/type_traits \ 
C:/MongoDB/src/third_party/boost/boost/typeof \ 
C:/MongoDB/src/third_party/boost/boost/units \ 
C:/MongoDB/src/third_party/boost/boost/unordered \ 
C:/MongoDB/src/third_party/boost/boost/utility \ 

DEFINES += _UNICODE \ 
    SYM_STATICLIB 

QMAKE_CFLAGS_RELEASE += /MT 
QMAKE_CXXFLAGS_RELEASE += /MT 
QMAKE_CFLAGS_DEBUG += /MTd 
QMAKE_CXXFLAGS_DEBUG += /MTd 

LIBS += -L$$PWD/../../../../../../MongoDB/src/third_party -lWS2_32 
LIBS += -L$$PWD/../../../../../../MongoDB/src/third_party -lDbgHelp 

CONFIG(debug, debug|release) { 
    LIBS += -LC:\MongoDB\build\win32\debug\client_build -lmongoclient 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/thread/build/msvc-10.0/debug/link-static/runtime-link-static/threading-multi/ -llibboost_thread-vc100-mt-sgd-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/date_time/build/msvc-10.0/debug/link-static/runtime-link-static/threading-multi/ -llibboost_date_time-vc100-mt-sgd-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/system/build/msvc-10.0/debug/link-static/runtime-link-static/ -llibboost_system-vc100-sgd-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/filesystem/build/msvc-10.0/debug/link-static/runtime-link-static/ -llibboost_filesystem-vc100-sgd-1_49 
} 

CONFIG(release, debug|release) { 
    LIBS += -LC:\MongoDB\build\win32\release\client_build -lmongoclient 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/thread/build/msvc-10.0/release/link-static/runtime-link-static/threading-multi/ -llibboost_thread-vc100-mt-s-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/date_time/build/msvc-10.0/release/link-static/runtime-link-static/threading-multi/ -llibboost_date_time-vc100-mt-s-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/system/build/msvc-10.0/release/link-static/runtime-link-static/ -llibboost_system-vc100-s-1_49 
    LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/filesystem/build/msvc-10.0/release/link-static/runtime-link-static/ -llibboost_filesystem-vc100-s-1_49 
} 

주 , 그리고 동적 런타임에 대비하여 빌드 될 메인 Qt 앱에서 해당 DLL을 사용하십시오.

Qt Creator가 "Program Files (x86)"경로에 공백을 포함하고 있기 때문에 수동으로 winsock을 복사하고 루트 폴더에 libs 파일을 포함시켜 수동으로 포함시켜야했습니다.

"몽고 C"대답이 아니라는 것을 깨달았지만, C++ 드라이버를 사용하는 C 드라이버를 사용하고 있다는 것을 언급 했으므로 내가 아는 것을 나눌 것이라고 생각했습니다. .