Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Database Connection Dialog

From Qt Wiki
Revision as of 15:14, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

General Database Connection Dialog

This code snippet shows how to implement a general database dialog that will prompt the user for general database connection properties (username, password, hostname, ecc.) as well as a combo with all available database drivers. The dialog provides also a signal that will pass the database connection (if established) so that third party components can use such connection.

Usage

Usage of the presented dialog is like the following:

The dialog allows for pre-initialization of form fields, as well as an auto-connect mode that make the connection to happen automatically if all the data is in place.
Please note that this dialog can be improved in several ways, and represents therefore a starting point for a more specific database connection dialog.

Auto-Connect mode

When the run() method is invoked an autoconnect mode can be specified as boolean value true. In such mode, if all the form data is filled, the dialog immediately attempts to connect to the database, and in the case it succeed the dialog is not shown to the user and the signal is emitted. In the case the form data is not complete or the connection cannot be established, the dialog is shown to the user. If the autoconnect mode is off (parameter = false) the dialog is always shown.

Source code

The following is the header file:

And the following is the class implementation:

Categories: