Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qt add a database sql into a project imported from cmake

Tags:

c++

qt

qt5

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

like image 410
Thierry Joel Avatar asked Jul 11 '16 20:07

Thierry Joel


People also ask

What is Qtsql?

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.

Does Qt use CMake?

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.


1 Answers

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)
like image 154
Velkan Avatar answered Nov 09 '22 00:11

Velkan