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
Qt SQL is an essential module which provides support for SQL databases. Qt SQL's APIs are divided into different layers: Driver layer. SQL API layer.
Qt relies on some bundled tools for code generation, such as moc for meta-object code generation, uic for widget layout and population, and rcc for virtual file system content generation. These tools may be automatically invoked by cmake(1) if the appropriate conditions are met.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With