Locate Functions

## Functions

QString | locate (const char *type, const QString &filename, const KInstance *instance=KGlobal::instance())
QString | locateLocal (const char *type, const QString &filename, const KInstance *instance=KGlobal::instance())
QString | locateLocal (const char *type, const QString &filename, bool createDir, const KInstance *instance=KGlobal::instance())

## Detailed Description

On The Usage Of 'locate' and 'locateLocal'.

Typical KDE applications use resource files in one out of three ways:

1) A resource file is read but is never written. A system default is supplied but the user can override this default in his local .kde directory:

// Code example
myFile = locate("appdata", "groups.lst");
myData = myReadGroups(myFile); // myFile may be null

2) A resource file is read and written. If the user has no local version of the file the system default is used. The resource file is always written to the users local .kde directory.

// Code example
myFile = locate("appdata", "groups.lst")
myData = myReadGroups(myFile);
...
doSomething(myData);
...
myFile = locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);

3) A resource file is read and written. No system default is used if the user has no local version of the file. The resource file is always written to the users local .kde directory.

// Code example
myFile = locateLocal("appdata", "groups.lst");
myData = myReadGroups(myFile);
...
doSomething(myData);
...
myFile = locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);

## Function Documentation

QString locate | ( | const char * | type,
|  | const QString & | filename,
|  | const KInstance * | instance = `KGlobal::instance()`
| ) |  |

related

This function is just for convenience. It simply calls instance->dirs()->findResource(type, filename).

Definition at line 1657 of file kstandarddirs.cpp.

QString locateLocal | ( | const char * | type,
|  | const QString & | filename,
|  | const KInstance * | instance = `KGlobal::instance()`
| ) |  |

related

This function is much like locate. However it returns a filename suitable for writing to. No check is made if the specified filename actually exists. Missing directories are created. If filename is only a directory, without a specific file, filename must have a trailing slash.

Definition at line 1663 of file kstandarddirs.cpp.

QString locateLocal | ( | const char * | type,
|  | const QString & | filename,
|  | bool | createDir,
|  | const KInstance * | instance = `KGlobal::instance()`
| ) |  |

related

This function is much like locate. No check is made if the specified filename actually exists. Missing directories are created if `createDir` is true. If filename is only a directory, without a specific file, filename must have a trailing slash.

Definition at line 1669 of file kstandarddirs.cpp.

KDE Home | KDE Accessibility Home | Description of Access Keys