2013-01-07 1 views
0

J'ai une URL YouTube codé (directement à la vidéo), par exemple:qurl et YouTube (Qt 4.8)

http%253A%252F%252Fr7---sn-xjpm-q0nl.c.youtube.com%252Fvideoplayback%253Fgcr%253Dde%2526ratebypass%253Dyes%2526newshard%253Dyes%2526source%253Dyoutube%2526fexp%253D920704%25252C912806%25252C928001%25252C922403%25252C922405%25252C929901%25252C913605%25252C929104%25252C929109%25252C913546%25252C913556%25252C908493%25252C908496%25252C920201%25252C913302%25252C919009%25252C911116%25252C901451%25252C902556%2526ipbits%253D8%2526key%253Dyt1%2526id%253De4b675c403014739%2526mv%253Dm%2526cp%253DU0hUTFVTVV9LUENONF9NTVlFOlVHOGtlTmJ2WWpt%2526mt%253D1357567034%2526itag%253D46%2526ms%253Dau%2526expire%253D1357587466%2526sparams%253Dcp%25252Cgcr%25252Cid%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Csource%25252Cupn%25252Cexpire%2526ip%253D46.59.194.67%2526upn%253DVaZiTmBJt0Y%2526sver%253D3%26quality%3Dhd1080%26itag%3D46%26fallback_host%3Dtc.v19.cache5.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26sig%3D6C3258197CB246FA9531E056083053B1B7EAA9C2.758C7B46E77C4B5CF5C7B0C5CBEDCB5F675559D7 

Cette URL ci-dessus est une variable QString "str", comment puis-je le mettre à QUrl?

QUrl url = QUrl::fromPercentEncoding(str.toUtf8()); 

ne fonctionne pas! Un

qDebug() << url.toString(); 

donne l'URL encodée (ci-dessus) et non l'humain affichable!

Répondre

0

Votre URL est encodée deux fois. %25 est la version codée de %. C'est pourquoi vous devez appeler deux fois le fromPercentEncoding.

http%253A%252F%252F devient http%3A%2F%2F après le premier tour et http:// après le second tour.

Exemple:

#include <QApplication> 
#include <QDebug> 
#include <QUrl> 

int main(int argc, char *argv[]) { 

    QApplication app(argc, argv); 
    QString str="http%253A%252F%252Fr7---sn-xjpm-q0nl.c.youtube.com%252Fvideoplayback%253Fgcr%253Dde%2526ratebypass%253Dyes%2526newshard%253Dyes%2526source%253Dyoutube%2526fexp%253D920704%25252C912806%25252C928001%25252C922403%25252C922405%25252C929901%25252C913605%25252C929104%25252C929109%25252C913546%25252C913556%25252C908493%25252C908496%25252C920201%25252C913302%25252C919009%25252C911116%25252C901451%25252C902556%2526ipbits%253D8%2526key%253Dyt1%2526id%253De4b675c403014739%2526mv%253Dm%2526cp%253DU0hUTFVTVV9LUENONF9NTVlFOlVHOGtlTmJ2WWpt%2526mt%253D1357567034%2526itag%253D46%2526ms%253Dau%2526expire%253D1357587466%2526sparams%253Dcp%25252Cgcr%25252Cid%25252Cip%25252Cipbits%25252Citag%25252Cratebypass%25252Csource%25252Cupn%25252Cexpire%2526ip%253D46.59.194.67%2526upn%253DVaZiTmBJt0Y%2526sver%253D3%26quality%3Dhd1080%26itag%3D46%26fallback_host%3Dtc.v19.cache5.c.youtube.com%26type%3Dvideo%252Fwebm%253B%2Bcodecs%253D%2522vp8.0%252C%2Bvorbis%2522%26sig%3D6C3258197CB246FA9531E056083053B1B7EAA9C2.758C7B46E77C4B5CF5C7B0C5CBEDCB5F675559D7"; 
    qDebug() << QUrl::fromPercentEncoding(str.toUtf8()); 
    qDebug() << QUrl::fromPercentEncoding(QUrl::fromPercentEncoding(str.toUtf8()).toUtf8()); 
    return app.exec(); 
} 
+0

C'est, merci! – user1955248