Search for usage in LXR

#include <KDbMessageHandler.h>

Public Member Functions

 KDbMessageGuard (const KDbResult &result, KDbMessageHandler *handler)
 KDbMessageGuard (KDbResultable *resultable)

Protected Attributes

Private *const d

Detailed Description

A guard class for transmitting messages based on KDbResult.

It's intended use is for top-level public methods in applications that have to display messages. Create it's instance on stack; at the end of the block, on KDbMessageGuard's destruction result will be checked. If it's not empty, error is passed to the associated message handler. The example below emits error message if result is not empty before .

class MyClass : ... public KDbResultable {
MyClass(KDbMessageHandler *handler) {
setMessageHandler(handler); // need ...
bool connectToProject() {
KDbMessageGuard mg(this); // MyClass is KDbResultable so this easy notation is possible
if (... something failed ...) {
m_result = KDbResult(tr("Operation failed."));
return false; // ~KDbMessageGuard called here, m_result is passed to messageHandler()
// ...
return true; // ~KDbMessageGuard called here is a no-op because there's no error in m_result

There are two equivalent variants of usage:

Definition at line 65 of file KDbMessageHandler.h.

Constructor & Destructor Documentation

◆ KDbMessageGuard() [1/2]

KDbMessageGuard::KDbMessageGuard ( KDbResultable resultable)

Builds a guard in the current code block using resultable Infromation from resultable will be used in ~KDbMessageGuard() to pass message to the resultable->messageHandler() handler if the handler is present and resultable->result().isError() == true.

resultable is required

Definition at line 35 of file KDbMessageHandler.cpp.

◆ KDbMessageGuard() [2/2]

KDbMessageGuard::KDbMessageGuard ( const KDbResult result,
KDbMessageHandler handler 

Builds a guard in the current code block using a reference to result and handler These will be used in ~KDbMessageGuard() is result.isError() == true.

handler is required

Definition at line 43 of file KDbMessageHandler.cpp.

The documentation for this class was generated from the following files:
KCOREADDONS_EXPORT void setMessageHandler(KMessageHandler *handler)
Interface for classes providing a result.
A guard class for transmitting messages based on KDbResult.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Aug 17 2022 04:05:00 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.