[SOLVED]QDesktopServices::openUrl(QUrl()) saying file doesn't exist, when it does



  • I'm trying to open a file with QDesktopServices::openUrl(QUrl()), I have a QString url with value "/home/username/my file.pdf", and when I run QDesktopServices::openUrl(QUrl(url)) I get the following error:
    gvfs-open: /home/username/mypercent20file.pdf: error opening location: Error when getting information for file '/home/username/mypercent20file.pdf': No such file or directory

    Now it's obviously encoding the string correctly, putting the percent20s in for spaces and whatnot, but it's saying that the file doesn't exist??? Is it maybe looking relative to my home directory or working directory or something? If it's looking relative to root directory (as it should with that url), then it should be able to find the file.



  • you have to convert path (/some/file/here) to url form (file:///some/path/here)

    @
    QString path = "/some/path/here";
    QUrl pathUrl = QUrl::fromLocalFile(path);
    QDesktopServices::openUrl(pathUrl);
    @



  • Ahhhh, see, I tried QUrl::toLocalFile, thinking it would convert to a local file url, it seems I got them mixed up. It's strange because the first thing I tried was
    @QString url = "file:///home/username/my file.pdf"@

    However when feeding that to QUrl it was replacing the file extention with a space o_O
    So it would convert to "file:///home/username/mypercent20file "

    Anyhow, thanks for the help, I really appreciate it! I've had nothing but good luck getting help on these forums ^_^



  • Please help me.
    How can i convert QT 4.8 code - To - QT 5.2 code that i indeed.

    --------------------------------------------Thax--------------------------------------------------

    #ifndef STDLOCATION_H
    #define STDLOCATION_H

    #include <QDir>
    #include <QFileInfo>
    #include <QDesktopServices>
    #include <QDateTime>
    #include "settings.h"

    #define SL_TRANSFERHISTORY "transfers.lst"
    #define SL_FILESTORAGEDIR "Received Files"
    #define SL_CACHEDIR "cache"
    #define SL_RESOURCE "lmc.rcc"
    #define SL_LANGDIR "lang"
    #define SL_THEMEDIR "themes"
    #define SL_GROUPFILE "group.cfg"
    #define SL_AVATARFILE "avt_local.png"
    #define SL_LOGDIR "logs"
    #define SL_TEMPCONFIG "lmctmpconf.ini"

    class StdLocation {
    public:

    static QString transferHistory(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_TRANSFERHISTORY);
    }

    static QString fileStorageDir(void) {
    lmcSettings settings;

    QString path = QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DocumentsLocation) + "/"SL_FILESTORAGEDIR);
    path = settings.value(IDS_FILESTORAGEPATH, path).toString();
    return path;
    }

    static QString cacheDir(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_CACHEDIR);
    }

    static QString libDir(void) {
    return QDir::toNativeSeparators(QDir::currentPath());
    }

    static QString resourceFile(void) {
    return QDir::toNativeSeparators(QDir::current().absoluteFilePath(SL_RESOURCE));
    }

    static QString resLangDir(void) {
    return ":/"SL_LANGDIR;
    }

    static QString sysLangDir(void) {
    return QDir::toNativeSeparators(QDir::currentPath() + "/"SL_LANGDIR);
    }

    static QString userLangDir(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_LANGDIR);
    }

    static QString resThemeDir(void) {
    return ":/"SL_THEMEDIR;
    }

    static QString sysThemeDir(void) {
    return QDir::toNativeSeparators(QDir::currentPath() + "/"SL_THEMEDIR);
    }

    static QString userThemeDir(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_THEMEDIR);
    }

    static QString groupFile(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_GROUPFILE);
    }

    static QString avatarFile(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_AVATARFILE);
    }

    static QString logDir(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::DataLocation) + "/"SL_LOGDIR);
    }

    static QString freeLogFile(void) {
    QString fileName = "lmc_" +
    QString::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch()) + ".log";
    return QDir::toNativeSeparators(logDir() + "/" + fileName);
    }

    static QString tempConfigFile(void) {
    return QDir::toNativeSeparators(QDesktopServices::storageLocation(
    QDesktopServices::TempLocation) + "/"SL_TEMPCONFIG);
    }
    };

    #endif // STDLOCATION_H


  • Lifetime Qt Champion

    ctsiitmail

    Please stop asking the same questions on every thread related to QDesktopServices, open your own thread asking for help.

    First thing you should do is follow the porting guide from Qt 5's documentation.



  • Please help me solve in QT 5.2
    Anyone help me to convert, Converter or translate software for qt 4.8 to qt 5.2

    facing warning:

    FileView has not been dexlared

    void updateProgress(FileView* view, qint64 currentPos);

    void setButtonState(FileView::TransferState state);

    Ui::TransferWindow ui;

    QList<FileView> pendingSendList;

    ui.setupUi(this);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.