Skip to content

Instantly share code, notes, and snippets.

@webmaster128
Created January 4, 2014 15:42
Show Gist options
  • Select an option

  • Save webmaster128/8256606 to your computer and use it in GitHub Desktop.

Select an option

Save webmaster128/8256606 to your computer and use it in GitHub Desktop.
The sample code shows how dangerous it can be to blindly copy a QString to a QUrl. Tested with Qt 5.1.1 and Qt 5.2.0 on Ubuntu.
QUrl dst;
QUrl src = QUrl::fromLocalFile("aPictureFile.jpg");
qDebug() << "INITIAL STATE";
qDebug() << "Source: " << src;
qDebug() << "Destination URL: " << dst;
dst = src;
qDebug() << "END STATE 1";
qDebug() << "Destination URL: " << dst;
qDebug() << "Destination local file: " << dst.toLocalFile();
dst = src.toLocalFile();
qDebug() << "END STATE 2";
qDebug() << "Destination URL: " << dst;
qDebug() << "Destination local file: " << dst.toLocalFile();
// INITIAL STATE
// Source: QUrl( "file:aPictureFile.jpg" )
// Destination URL: QUrl( "" )
// END STATE 1
// Destination URL: QUrl( "file:aPictureFile.jpg" )
// Destination local file: "aPictureFile.jpg"
// END STATE 2
// Destination URL: QUrl( "aPictureFile.jpg" )
// Destination local file: ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment