'lightweight' QDir::isAbsolutePath replacement ?

Ralf Habacker ralf.habacker at freenet.de
Thu Mar 6 19:54:41 CET 2008


Ralf Habacker schrieb:
> Hi,
>
> there are several places in the kde code which needs a check if a path 
> is absolute. On unix this is mainly done by using  
> QString::startsWith('/'), which does not work as expected on windows.
>
> The only static method Qt provides to handle this platform independent 
> is QDir::isAbsolutePath(). Unfortunally this method seems to be very 
> time expensive because it creates a temporary QDir instance.
One little correction: I fact QDir::isAbsolutePath() creates a QFileInfo 
instance instead of QDir but the problems still remains.

qdir.h
    static bool isRelativePath(const QString &path);
    inline static bool isAbsolutePath(const QString &path) { return 
!isRelativePath(path); }

qdir.cpp
bool QDir::isRelativePath(const QString &path)
{
    return QFileInfo(path).isRelative();
}

Ralf




More information about the Kde-windows mailing list