Creating a database
In this recipe, we will be prompting the user to enter a database name, followed by clicking the push button. Upon clicking the push button, if the specified database does not exist, it is created and, if it already exists, it is connected.
How to do it…
Follow this step-by-step procedure to create a database in SQLite:
- Let's create an application based on the
Dialog without Buttons
template. - Add two
QLabel
widgets, oneQLineEdit
widget, and oneQPushButton
widget to the form by dragging and dropping twoLabel
widget, oneLine Edit
widget, and aPush Button
widget on the form. - Set the
text
property of the firstLabel
widget toEnter database name
. - Delete the
text
property of the secondLabel
widget because this is established. - Set the
objectName
property of theLine Edit
widget tolineEditDBName
. - Set the
objectName
property of thePush Button
widget topushButtonCreateDB
. - Set the
objectName
property of the secondLabel
widget tolabelResponse
. - Save the application by name as
demoDatabase...