QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Member Functions | List of all members
QtDataSync::DatabaseRef Class Reference

A wrapper around QSqlDatabase to manage the connections. More...

#include <defaults.h>

Public Member Functions

 DatabaseRef ()
 Default constructor. Constructs an invalid database reference.
 
 DatabaseRef (DatabaseRef &&other) noexcept
 Move constructor.
 
DatabaseRefoperator= (DatabaseRef &&other) noexcept
 Move assignment operator.
 
bool isValid () const
 Returns true if this reference points to a valid database.
 
QSqlDatabase database () const
 Returns the database that is managed by this reference.
 
 operator QSqlDatabase () const
 Implicit cast operator to the managed database.
 
QSqlDatabaseoperator-> () const
 Arrow operator to access the database.
 
void drop ()
 Drops the reference to the database early.
 

Detailed Description

A wrapper around QSqlDatabase to manage the connections.

Internally, this class holds a reference to a sqlite database. The first reference created form a Defaults instance will also create the database connection. From there on, the references to the database are counted with this class. Once the last instance gets destroyed, the database connection closes and gets deleted. Because of this it's important to not extract the QSqlDatabase from this class to "permanent" variable. Try to use the reference class where possible and only pass the internal database to scoped objects.

See also
Defaults::aquireDatabase, QSqlDatabase

Definition at line 28 of file defaults.h.


The documentation for this class was generated from the following file: