template<typename T>
QgsConnectionPoolGroup class

Template that stores data related to a connection to a single server or datasource.

It is assumed that following functions exist:

  • void qgsConnectionPool_ConnectionCreate(QString name, T& c) ... create a new connection
  • void qgsConnectionPool_ConnectionDestroy(T c) ... destroy the connection
  • QString qgsConnectionPool_ConnectionToName(T c) ... lookup connection's name (path)
  • void qgsConnectionPool_InvalidateConnection(T c) ... flag a connection as invalid
  • bool qgsConnectionPool_ConnectionIsValid(T c) ... return whether a connection is valid

Because of issues with templates and QObject's signals and slots, this class only provides helper functions for QObject-related functionality - the place which uses the template is resonsible for:

  • being derived from QObject
  • calling initTimer( this ) in constructor
  • having handleConnectionExpired() slot that calls onConnectionExpired()
  • having startExpirationTimer(), stopExpirationTimer() slots to start/stop the expiration timer

For an example on how to use the template class, have a look at the implementation in Postgres/SpatiaLite providers.

Constructors, destructors, conversion operators

QgsConnectionPoolGroup(const QgsConnectionPoolGroup& other) deleted
QgsConnectionPoolGroup cannot be copied.

Public functions

auto acquire(int timeout, bool requestMayBeNested) -> T
Try to acquire a connection for a maximum of timeout milliseconds.
auto operator=(const QgsConnectionPoolGroup& other) -> QgsConnectionPoolGroup& deleted
QgsConnectionPoolGroup cannot be copied.

Function documentation

template<typename T>
T QgsConnectionPoolGroup<T>::acquire(int timeout, bool requestMayBeNested)

Try to acquire a connection for a maximum of timeout milliseconds.

Returns initialized connection or nullptr if unsuccessful

If timeout is a negative value the calling thread will be blocked until a connection becomes available. This is the default behavior.