Created
January 4, 2014 15:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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