Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFile accessing samba shared file (Qt on linux )
Forum Updated to NodeBB v4.3 + New Features

QFile accessing samba shared file (Qt on linux )

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 10.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saeed144
    wrote on 19 Feb 2012, 11:48 last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 19 Feb 2012, 13:47 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        saeed144
        wrote on 19 Feb 2012, 14:57 last edited by
        #3

        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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on 19 Feb 2012, 15:07 last edited by
          #4

          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.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            saeed144
            wrote on 20 Feb 2012, 09:23 last edited by
            #5

            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
            @

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on 20 Feb 2012, 09:45 last edited by
              #6

              [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.

              1 Reply Last reply
              0

              1/6

              19 Feb 2012, 11:48

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved