From kde-core-devel Fri Oct 17 22:44:19 2014 From: Kevin Kofler Date: Fri, 17 Oct 2014 22:44:19 +0000 To: kde-core-devel Subject: QUrl from a string (porting KUrl constructor or KCmdLineArgs::url) Message-Id: X-MARC-Message: https://marc.info/?l=kde-core-devel&m=141358589725749 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