This class allows representation of the result of a process and/or function. More...
#include <GCF3/GCFGlobal>
Public Member Functions | |
| Result () | |
| Result (bool val) | |
| Result (bool val, const QString &code, const QString &msg=QString(), const QVariant &data=QVariant()) | |
| Result (const Result &other) | |
| bool | isSuccess () const |
| QString | code () const |
| QString | message () const |
| QVariant | data () const |
| Result & | operator= (const Result &other) |
| Result & | operator= (bool val) |
| bool | operator== (const Result &other) const |
| QString | toString () const |
Detailed Description
This class can be used to capture in one object the following
- success/failure flag
- error code and error message in case of failure
- data in case of success
This class can be used as a return data-type in almost any function, specially functions that return true/false. The benefit of using this class in such a function is that you can return a error code+message incase of failure and concrete result in case of success.
Example:
This would allow the caller of your method to get a sense of what went wrong, incase of an error.
Example:
Constructor & Destructor Documentation
| GCF::Result::Result | ( | ) |
Default constructor. Constructs result with success-flag as false.
| GCF::Result::Result | ( | bool | val | ) |
Constructs result with success-flag as val.
- Parameters
-
val success-flag of the result
| GCF::Result::Result | ( | bool | val, |
| const QString & | code, | ||
| const QString & | msg = QString(), |
||
| const QVariant & | data = QVariant() |
||
| ) |
Constructs a result from the given parameters
- Parameters
-
val success-flag of the result code erorr-code of the result msg error-message of the result data data (or result) of the result
| GCF::Result::Result | ( | const Result & | other | ) |
Copy constructor
Member Function Documentation
| bool GCF::Result::isSuccess | ( | ) | const |
- Returns
- success-flag of the result
| QString GCF::Result::code | ( | ) | const |
- Returns
- error code of the result, if isSuccess() returns false. Empty string otherwise.
| QString GCF::Result::message | ( | ) | const |
- Returns
- error message of the result, if isSuccess() returns false. Empty string otherwise.
| QVariant GCF::Result::data | ( | ) | const |
- Returns
- data of the result, if isSuccess() return true. Invalid
QVariantotherwise.
| GCF::Result & GCF::Result::operator= | ( | const Result & | other | ) |
Assignment operator
| GCF::Result & GCF::Result::operator= | ( | bool | val | ) |
Assignment operator
| bool GCF::Result::operator== | ( | const Result & | other | ) | const |
Comparison operator
| QString GCF::Result::toString | ( | ) | const |
- Returns
- a string representation of the result.
- Note
operator<<onQDebughas been overloaded to print into debug output string representations of GCF::Result. So you can stream this object intoqDebug(). Example:GCF::Result result = ...qDebug() << result;

