[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    QUrl from a string (porting KUrl constructor or KCmdLineArgs::url)
From:       Kevin Kofler <kevin.kofler () chello ! at>
Date:       2014-10-17 22:44:19
Message-ID: m1s644$o6i$1 () ger ! gmane ! org
[Download RAW message or body]

Hi,

even after reading the porting guide and listening to David Faure's Akademy 
talk, I am still unsure about what the best way is to get a URL from a 
string, supporting:
* absolute URL (with explicit scheme:// only)
* absolute local file path
* relative path: everything neither an absolute URL nor an absolute local
  file path is assumed to be a relative path (relative to the local CWD)
as both KUrl::KUrl(QString) and KCmdLineArgs::url did (in slightly 
different, but similar ways).

This is needed, e.g., when processing command-line arguments.

I see the following APIs available:
* QUrl::QUrl(QString): accepts an absolute URL or a relative URL, but the
                       documentation explicitly warns that it must not be
                       used on absolute local file paths
* QUrl::fromLocalFile: accepts an absolute local file path or a relative
                       local file path, but does not accept a URL
* QUrl::fromUserInput: seems closest to what I want, but assumes a web
                       browser context and in particular assumes http:// in
                       situations that should really be treated as a
                       relative path in most contexts

So, is there any function anywhere that does what I want? Or do I have to 
write something like:
QDir::isAbsolutePath(str) ? QUrl::fromLocalFile(str) : QUrl(str)
? (And is QUrl(str) even OK for relative file paths or is there a difference 
between a relative URL and a relative local file path that I'm missing?)

        Kevin Kofler

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic