PDA

View Full Version : Opening an URL that contains accents



Nyphel
23rd June 2007, 22:35
Hi,

I've wrote a small application that search for movies in my computer, list them, order the list and display the list to the user (using a a QTreeWidget). When the user double clic a movie name, my application use the QDesktopServices in order to launch the movie.

Here is the sample code used to launch the movie :


QString path_to_a_movie = "N:/The movies/666 - La malédiction";

QUrl my_url;
my_url = QUrl::fromLocalFile(path_to_a_movie);

QDesktopServices::openUrl(my_url);


If the [path_to_a_movie] contains accents, like in the example, the movie isn't launched.
I don't understand how to resolve this problem... Has someone an idea ?

jacek
23rd June 2007, 22:46
If you construct QStrings this way, you have to set a codec using QTextCodec::codecForCStrings() to let Qt know which codec to use for string literals.

Nyphel
23rd June 2007, 23:02
In reality, here is the slot that handle double clics on a movie name in the QtreeWidget :



void interface_impl::SLOT_launch_movie(QTreeWidgetItem *item, int column)
{
QUrl my_url;
my_url = QUrl::fromLocalFile(item->text(1));

QDesktopServices::openUrl(my_url);
}


So the QString is directly returned by a QTreeWidgetItem, and I suppose - but I don't know - that there is no char* / QByteArray convertion :o

jacek
24th June 2007, 01:09
Are those strings displayed properly in the QTreeWidget?

Nyphel
24th June 2007, 11:15
Yes, they are ;)

Perhaps the openURL function has not been written to accept accents... Like generally there is no accentuation in web URLs.

jacek
24th June 2007, 16:34
Which Qt version do you use?

Nyphel
25th June 2007, 08:26
Qt 4.2.3, I will probably use the Qt 4.3 next week.

jacek
25th June 2007, 21:14
It seems that this problem was fixed in Qt 4.3.0: http://trolltech.com/developer/task-tracker/index_html?method=entry&id=141352

Nyphel
26th June 2007, 08:13
Oh yes, thank you for this tip ! :)