In this recipe, we will learn how to connect our Qt 5 application to the SQL Server.
Connecting to a database
How to do it...
Connecting to SQL Server in Qt is really simple:
- Open Qt Creator and create a new Qt Widgets Application project.
- Open your project file (.pro) and add the sql module to your project, like so:
QT += core gui sql
- Open mainwindow.ui and drag seven label widgets, a combo box, and a checkbox to the canvas. Set the text properties of four of the labels to Name:, Age:, Gender:, and Married:. Then, set the objectName properties of the rest to name, age, gender, and married. There is no need to set the object name for the previous four labels, because they're for display purposes only:
- Open mainwindow...