'qt add a database sql into a project imported from cmake
Normally, to add a database to qt, we would go to the .pro file and add sql, but the project am working on was imported from cmake, so it does not have a .pro file. Rather it has a CMakeLists.txt file and i want to connect it to an sqlite database. Can anyone help me out. Thanks
Solution 1:[1]
It's Sql
component to add to the find_package()
command and Qt5::Sql
to the target_link_libraries()
command.
Search for something like that:
find_package(Qt5 REQUIRED COMPONENTS Core Quick Sql)
or like that:
find_package(Qt5Sql REQUIRED)
And the target_link_libraries()
:
target_link_libraries(myprogram Qt5::Core Qt5::Quick Qt5::Sql)
Solution 2:[2]
I searched for a very long time for a solution to the undefined symbol error with QSqlDatabase and tried many a different cmake setting ranging from link_directories over set(SQLite_DIR and get_target_property to aux_source_directory. Turns out it really suffices to use the above mentioned two additions to the cmakelists file. But you need to do a complete clean to make it work on the Mac. Delete the Debug/ Release directory.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Velkan |
Solution 2 |