Qt-interest Archive, May 2007
How to handle '?' in QUrl (Qt4)
Message 1 in thread
Hi
I've some files which contain '?' character in their name. I use
QUrl::fromLocaFile() to construct QUrl object. But when I again
convert QUrl to QString (local file) using QUrl::toLocalFile(), part
of file name following '?' character is removed. An I doing something
wrong?
Local file -> /songs1/Are You Sure You Want To Be Famous?.flac
QUrl -> file:///songs1/Are You Sure You Want To Be Famous?.flac
QUrl::toLocalFile() -> /songs1/Are You Sure You Want To Be Famous
Any suggestions?
Thanks
--
[ signature omitted ]
Message 2 in thread
formating options?....
QUrl::RemoveQuery The query part of the URL (following a '?'
character) is removed.
Yogesh M a Ãcrit :
> Hi
>
> I've some files which contain '?' character in their name. I use
> QUrl::fromLocaFile() to construct QUrl object. But when I again
> convert QUrl to QString (local file) using QUrl::toLocalFile(), part
> of file name following '?' character is removed. An I doing something
> wrong?
> Local file -> /songs1/Are You Sure You Want To Be Famous?.flac
> QUrl -> file:///songs1/Are You Sure You Want To Be Famous?.flac
> QUrl::toLocalFile() -> /songs1/Are You Sure You Want To Be Famous
>
> Any suggestions?
>
>
> Thanks
>
--
[ signature omitted ]
Message 3 in thread
On 15/05/07, veronique.lefrere@xxxxxx <veronique.lefrere@xxxxxx> wrote:
>
>
>
> formating options?....
> QUrl::RemoveQuery The query part of the URL (following a '?'
> character) is removed.
>
> Yogesh M a Ãcrit :
>
> > Hi
> >
> > I've some files which contain '?' character in their name. I use
> > QUrl::fromLocaFile() to construct QUrl object. But when I again
> > convert QUrl to QString (local file) using QUrl::toLocalFile(), part
> > of file name following '?' character is removed. An I doing something
> > wrong?
> > Local file -> /songs1/Are You Sure You Want To Be Famous?.flac
> > QUrl -> file:///songs1/Are You Sure You Want To Be Famous?.flac
> > QUrl::toLocalFile() -> /songs1/Are You Sure You Want To Be Famous
> >
> > Any suggestions?
> >
> >
> > Thanks
> >
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
QUrl::toLocalFile() has no formatting options. My need is to convert
to local path, not to convert using QUrl::toString() to show to user.
--
[ signature omitted ]
Message 4 in thread
Hi,
> > > Local file -> /songs1/Are You Sure You Want To Be Famous?.flac
> > > QUrl -> file:///songs1/Are You Sure You Want To Be Famous?.flac
> > > QUrl::toLocalFile() -> /songs1/Are You Sure You Want To Be Famous
You are probably using it wrong. When setting the URLs, take a look at
QUrl::toPercentEncoding () and QUrl::fromPercentEncoding ().
The URL-String must be "percent-Encoded" otherwise any "?" will separate
the Query part. Spaces are automatically converted in tolerant mode though
but actually the would have to be written as "%20" as well. Use the above
mentioned functions and it will probably work for you :-)
Regards,
Malte
--
[ signature omitted ]
Message 5 in thread
---------- Forwarded message ----------
From: Yogesh M <yogeshm02@xxxxxxxxx>
Date: 15-May-2007 19:30
Subject: Re: How to handle '?' in QUrl (Qt4)
To: Malte Witt <malte.witt@xxxxxxxxxxxxx>
On 15/05/07, Malte Witt <malte.witt@xxxxxxxxxxxxx> wrote:
> Hi,
>
> > > > Local file -> /songs1/Are You Sure You Want To Be Famous?.flac
> > > > QUrl -> file:///songs1/Are You Sure You Want To Be Famous?.flac
> > > > QUrl::toLocalFile() -> /songs1/Are You Sure You Want To Be Famous
>
> You are probably using it wrong. When setting the URLs, take a look at
> QUrl::toPercentEncoding () and QUrl::fromPercentEncoding ().
> The URL-String must be "percent-Encoded" otherwise any "?" will separate
> the Query part. Spaces are automatically converted in tolerant mode though
> but actually the would have to be written as "%20" as well. Use the above
> mentioned functions and it will probably work for you :-)
>
> Regards,
> Malte
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
I'm using it like this: -
QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
Famous?.flac");
QString localPath = url.toLocalFile();
--
[ signature omitted ]
Message 6 in thread
On 15.05.07 19:31:55, Yogesh M wrote:
> I'm using it like this: -
> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> Famous?.flac");
> QString localPath = url.toLocalFile();
This sounds like a bug to me, which version Qt are you using?
Andreas
--
[ signature omitted ]
Message 7 in thread
On 15/05/07, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 15.05.07 19:31:55, Yogesh M wrote:
> > I'm using it like this: -
> > QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> > Famous?.flac");
> > QString localPath = url.toLocalFile();
>
> This sounds like a bug to me, which version Qt are you using?
>
> Andreas
>
> --
> You will probably marry after a very brief courtship.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Sorry, leaving the previously shown usage (which is doing perfect),
the problem seems to be in the way playlist is loaded/saved.
While adding an item to playlist, I do
QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
Famous?.flac");
(url.toLocalFile() does return "/songs1/Are You Sure You Want To Be
Famous?.flac")
But when playlist is saved (written to file) QUrl is converted to
QString via QUrl::toQString(FormattingOptions options = None )
which gives "file:///songs1/Are You Sure You Want To Be Famous?.flac"
While playlist is loaded QUrl is created as
QUrl("file:///songs1/Are You Sure You Want To Be Famous?.flac");
(Now url.toLocalFile() returns "/songs1/Are You Sure You Want To Be Famous")
Thanks to all for replies and sorry for incorrect/partial information
given earlier.
Thanks again...
--
[ signature omitted ]
Message 8 in thread
On 15.05.07 20:03:27, Yogesh M wrote:
> On 15/05/07, Andreas Pakulat <apaku@xxxxxx> wrote:
> >On 15.05.07 19:31:55, Yogesh M wrote:
> >> I'm using it like this: -
> >> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> >> Famous?.flac");
> >> QString localPath = url.toLocalFile();
> >
> >This sounds like a bug to me, which version Qt are you using?
>
> Sorry, leaving the previously shown usage (which is doing perfect),
> the problem seems to be in the way playlist is loaded/saved.
Yes.
> While adding an item to playlist, I do
> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> Famous?.flac");
> (url.toLocalFile() does return "/songs1/Are You Sure You Want To Be
> Famous?.flac")
>
> But when playlist is saved (written to file) QUrl is converted to
> QString via QUrl::toQString(FormattingOptions options = None )
> which gives "file:///songs1/Are You Sure You Want To Be Famous?.flac"
>
> While playlist is loaded QUrl is created as
> QUrl("file:///songs1/Are You Sure You Want To Be Famous?.flac");
> (Now url.toLocalFile() returns "/songs1/Are You Sure You Want To Be Famous")
Which is correct, because yu gave a full url to QUrl and thus it expects
the ? to be separateing the path from the query. I think you already
know the fix, just stating it here in case somebody finds this
discussion later: Instead of toString() which is intended for displaying
the url to the user the saving-code should use toLocalFile().
Andreas
--
[ signature omitted ]
Message 9 in thread
On 15/05/07, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 15.05.07 20:03:27, Yogesh M wrote:
> > While adding an item to playlist, I do
> > QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> > Famous?.flac");
> > (url.toLocalFile() does return "/songs1/Are You Sure You Want To Be
> > Famous?.flac")
> >
> > But when playlist is saved (written to file) QUrl is converted to
> > QString via QUrl::toQString(FormattingOptions options = None )
> > which gives "file:///songs1/Are You Sure You Want To Be Famous?.flac"
> >
> > While playlist is loaded QUrl is created as
> > QUrl("file:///songs1/Are You Sure You Want To Be Famous?.flac");
> > (Now url.toLocalFile() returns "/songs1/Are You Sure You Want To Be Famous")
>
> Which is correct, because yu gave a full url to QUrl and thus it expects
> the ? to be separateing the path from the query. I think you already
> know the fix, just stating it here in case somebody finds this
> discussion later: Instead of toString() which is intended for displaying
> the url to the user the saving-code should use toLocalFile().
>
> Andreas
>
> --
> Good news. Ten weeks from Friday will be a pretty good day.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
But, I can't use toLocalFile() while writing the playlist because I'm
using XML playlist format and need to write fully valid urls.
Please clear some more doubts,
#1, documentation for QUrl ( const QString & url ) says, "url is
assumed to be in human readable representation, with no percent
encoding".
#2, constructing QUrl from QUrl::fromEncoded( const QByteArray & input
), should I convert QString (locaded from xml) to QByteArray through
QString::toQAscii()
If possible, can you please give me a snippet of code?
Thanks
--
[ signature omitted ]
Message 10 in thread
On 15.05.07 20:41:54, Yogesh M wrote:
> On 15/05/07, Andreas Pakulat <apaku@xxxxxx> wrote:
> >On 15.05.07 20:03:27, Yogesh M wrote:
> >> While adding an item to playlist, I do
> >> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> >> Famous?.flac");
> >> (url.toLocalFile() does return "/songs1/Are You Sure You Want To Be
> >> Famous?.flac")
> >>
> >> But when playlist is saved (written to file) QUrl is converted to
> >> QString via QUrl::toQString(FormattingOptions options = None )
> >> which gives "file:///songs1/Are You Sure You Want To Be Famous?.flac"
> >>
> >> While playlist is loaded QUrl is created as
> >> QUrl("file:///songs1/Are You Sure You Want To Be Famous?.flac");
> >> (Now url.toLocalFile() returns "/songs1/Are You Sure You Want To Be Famous")
> >
> >Which is correct, because yu gave a full url to QUrl and thus it expects
> >the ? to be separateing the path from the query. I think you already
> >know the fix, just stating it here in case somebody finds this
> >discussion later: Instead of toString() which is intended for displaying
> >the url to the user the saving-code should use toLocalFile().
>
> But, I can't use toLocalFile() while writing the playlist because I'm
> using XML playlist format and need to write fully valid urls.
Then you need to write the urls out using toEncoded() to properly encode
the ? in the filename using a %<2-digit> escape and if you need a
QString from that use QString::fromAscii().
> Please clear some more doubts,
> #1, documentation for QUrl ( const QString & url ) says, "url is
> assumed to be in human readable representation, with no percent
> encoding".
Right, thats what the docs say, what was the question?
> #2, constructing QUrl from QUrl::fromEncoded( const QByteArray & input
> ), should I convert QString (locaded from xml) to QByteArray through
> QString::toQAscii()
Yes. The reason is simply because toEncoded() does it the other way
around, i.e. encode the url by changing all non-ascii characters to
their %<foo> encoded form.
> If possible, can you please give me a snippet of code?
Not really, because I don't know how your code looks like. And I
believe you're very much capable of putting url.toEncoded() and
QUrl::fromEncoded(somestring.toAscii()) at the right places.
Andreas
--
[ signature omitted ]
Message 11 in thread
On 15/05/07, Andreas Pakulat <apaku@xxxxxx> wrote:
> On 15.05.07 20:41:54, Yogesh M wrote:
> > #2, constructing QUrl from QUrl::fromEncoded( const QByteArray & input
> > ), should I convert QString (locaded from xml) to QByteArray through
> > QString::toQAscii()
>
> Yes. The reason is simply because toEncoded() does it the other way
> around, i.e. encode the url by changing all non-ascii characters to
> their %<foo> encoded form.
>
> > If possible, can you please give me a snippet of code?
>
> Not really, because I don't know how your code looks like. And I
> believe you're very much capable of putting url.toEncoded() and
> QUrl::fromEncoded(somestring.toAscii()) at the right places.
>
> Andreas
>
>
>
I was asking for code because to/fromEncoded() was also not giving
results. Then i checked its usage with a small test programme and on
deeper probe found out that there was one more place where i was not
using toEncoded(). Now everything is working file.
Thanks to all for your valuable inputs.
PS: Seems that I should always assume that problem is on my part ;)
--
[ signature omitted ]
Message 12 in thread
> I'm using it like this: -
> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> Famous?.flac");
> QString localPath = url.toLocalFile();
I just tried your example with Qt 4.2.3-commercial (Windows) -> Works
quite well :-)
Are you using an older version of Qt?
Regards,
Malte
--
[ signature omitted ]
Message 13 in thread
On 15.05.07 19:31:55, Yogesh M wrote:
> I'm using it like this: -
> QUrl url = QUrl::fromLocalFile("/songs1/Are You Sure You Want To Be
> Famous?.flac");
> QString localPath = url.toLocalFile();
JFTR, the following works here with Qt4.3rc1:
,----
| #include <QUrl>
| #include <QDebug>
| int main(int, char**)
| {
| QString f("foo?.mp3");
| QUrl u = QUrl::fromLocalFile(f);
| qDebug() << f << u << u.toLocalFile();
| }
`----
Andreas
--
[ signature omitted ]