QFile accessing samba shared file (Qt on linux )



  • Dear all,

    I'm developing Qt 4.7.4 in Linux, trying to access a file in other linux samba server.
    The code on windows works like a charm, but still not in Linux,
    please let me know who can I work it out,

    @
    QString cAudio = "smb://192.168.0.2/audioshare/audiofile.wav";
    QFile cAudioFile(cAudio);
    if (cAudioFile.exists())
    QMessageBox::about(NULL, "cAudioFile", "file exists"+cAudio);
    else
    QMessageBox::about(NULL, "cAudioFile", "file missing"+cAudio);
    @

    The file is easily opened in VLC player, and the samba folder/file does not need any user/password.
    @QString cAudio = "//192.168.0.2/audioshare/audiofile.wav";@

    did not work either.
    But it works for local files like
    @QString cAudio = "/home/user1/audio/audiofile.wav";@

    BTW, I have set current directory to
    @QDir::setCurrent(QCoreApplication::applicationDirPath());@

    in the main program.

    Thanks in advance,
    Saeed144


  • Moderators

    QFile does not support non-local files.

    You can mount the resource locally and then access the data. There are also libraries like KIO Slaves from KDE and gnomeVFS from gnome to transparently access data not in the local file system.



  • Dear Tobias,
    As I said, running the code in Windows, works OK. I have to change the QFile path so that Windows understands it.

    @ QFile cAudioFile("\\192.168.0.2\audioshare\text.txt");
    if (cAudioFile.exists())
    QMessageBox::about(NULL, "1", "exists");
    else
    QMessageBox::about(NULL, "1", "not exists");@

    It's tricky, because, in windows I can read the file, shared on Linux, but I can't read it in Linux!

    BTW, gnomeVFS is deprecated based on wikipedia, and I should use GIO,

    Thanks for the reply,
    Saeed144



  • UNC file paths are supported by Windows natively. So it's no surprise that those work.

    The libc/stdlib functions on Linux do not support remote filesystems, as Tobias mentioned. So it does not work unless you have mounted that share to the local filesystem already.

    Comparing Windows and Linux here is comparing apples and oranges. What works on one OS, does not necessarily work on the other.



  • Being a software developer, I have to develop for both operating systems, though I personally prefer linux.

    It was interesting for me to see how OS can affect the behavior of a Cross-platform framework like Qt.
    Didn't mean to compare the operating systems in this matter,

    Anyway, thanks for the help, here is my code,

    @#ifdef Q_OS_LINUX
    cAudioPath = "/home/user/audioshare/";
    #endif
    #ifdef Q_OS_WIN32
    cAudioPath = "\\192.168.0.2\audioshare\";
    #endif
    @



  • [quote author="saeed144" date="1329729808"]Being a software developer, I have to develop for both operating systems, though I personally prefer linux.

    It was interesting for me to see how OS can affect the behavior of a Cross-platform framework like Qt.
    [/quote]

    Well, the framework cannot give you a totally OS-independent environment, at some point you have to deal with your deploy environment. For instance, Windows allows unit letters (C:) while *nix does not.
    My opinion is that, in order to be as much portable as possible, your application should not use two different paths but a single one which correspond to either a mount point or a link and is configured at the time the application is deployed.


Log in to reply
 

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