Sohag Developer PostgreSQL Database Applications

Build Powerful Robust Database Applications

sohag developer Simple Template code

Wed, 07/12/2017 - 12:54 - amr

Sohag Developer For PostgreSQL generates the Qt project files according to three templates theses templates are
1- Basic
2- Simple
3- Sohag Save Point

You can find them in the Generate button on the toolbar or the Generate menu

Note that Qt project file (.pro file) and main function (main.cpp) file are identical in the three templates the differnce is only in the Qt Designer form (.ui file that contains the gui widgets) and the generated class code that contains the SQL DML methods to mainupalte the database table data.
View Qt Project generated files for more information.

In this topic we will explore the generated project files of the Simple Template.

Suppose that we have the following Postgesql database table.

Database Table Structure

CREATE TABLE public.employees
  employee_id serial NOT NULL,
  employee_name character varying(500),
  gender integer,
  birth_date date,
  department_id integer,
  job_id integer,
  CONSTRAINT employees_pkey PRIMARY KEY (employee_id)

The generated Qt Designer Form (.ui File)

Qt Designer Form (.ui File)
The generated Qt Designer Form will contain two widgets for each selected column from the database tabel
One Widget is a QLabel widget and it will contain the label for the Other widget which will conatins the column data that will be mainupalted.
In addition the Qt Designer database form will contain some buttons (Query button, New button, Delete button, Save button, Close button) to execute the simple functionality to the form.

The generated Qt Designer Form is laid out in a QGridLayout.
The following image shows the generated Qt Designer form (,ui file) opend using Qt Creator.

The generated Qt/C++ class header file .h
The header file of the basic template class contains definitions for the class methods.
View the header (.h) file here

The generated Qt/C++ class implemenation file .cpp is
View the implemenation (.cpp) file here

Generated Class Methods


This method clears the form widgets to make of the fields empty.

toVarinat(QString string)

This method converts empty QString to NULL value to store it in the database column as null. If the Qstring is empty it will return a NULL QVariant else it will return a QVariant of the QString value.
This method is used in insert and update.

toString(QVariant value)

This method is used to convert the null values stored in the database field into empty Qstring.
In some versions of Qt casting QVariant of null value to string returns a none empty string the returned value will be 0 or 0.00 or any other value depending of the data type of the field.
Casting null Inegter to 0 may be useful sometimes but it may cause a problem as an example if the field is a foreign key column field.


This method contains the insert statement and binding query values to execute the query and insert values to the database table.


This method contains the update statement and binding query values to execute the query and update values in the database table.

remove() Mehod

This method contains the delete statement and binding query values to execute the query and delete values from the database table.

query() Mehod

This method contains the query statement and binding query values to execute the query and retrieve values from the database table and set the widgets values with these values.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.