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. Can not open file With QFile Class.
Forum Updated to NodeBB v4.3 + New Features

Can not open file With QFile Class.

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 6 Posters 4.1k 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.
  • G Offline
    G Offline
    Gaurav Badgujar
    wrote on 20 Dec 2016, 09:22 last edited by Gaurav Badgujar
    #1

    Hello,

    If we pass string like "D:\TestFoldler.docx:GauravData:$DATA" then we can write content in File.

    Example:-
    QFile file("D:\TestFoldler.docx:GauravData:$DATA" );
    file.open(QIODevice::WriteOnly);
    with this we can write content in file.

    but if we pass string like "\\nas\files\gauravFolder.docx:GauravData:$DATA" its not work.

    Example:-
    QFile file("\\nas\files\gauravFolder.docx:GauravData:$DATA" );
    file.open(QIODevice::WriteOnly);

    with this we can not write content in file. we can not open file.

    please Do needful.

    Regards,
    Gaurav Badgujar.

    J 1 Reply Last reply 20 Dec 2016, 10:00
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 20 Dec 2016, 09:33 last edited by mrjj
      #2

      Hi
      in c++ the

      \ has a special meaning. its called escaping
      so to have it in code you must use 2
      QFile("D:\\TestFoldler\\GauravData" );
      

      or use the Qt syntax using the other way. ( and just one)
      QFile("D:/TestFoldler/GauravData" );

      also
      "TestFoldler:GauravData:$DATA"
      is not a valid filename on windows.

      on linux its other way
      /nas/files/gauravFolder

      so make sure path is indeed correct.

      1 Reply Last reply
      2
      • V Offline
        V Offline
        VRonin
        wrote on 20 Dec 2016, 09:44 last edited by
        #3

        to add to @mrjj if you want to use those paths without duplicating or reversing the slashes you can use raw strings: QFile file(R"(\nas\files\gauravFolder:GauravData:$DATA)" );

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • G Gaurav Badgujar
          20 Dec 2016, 09:22

          Hello,

          If we pass string like "D:\TestFoldler.docx:GauravData:$DATA" then we can write content in File.

          Example:-
          QFile file("D:\TestFoldler.docx:GauravData:$DATA" );
          file.open(QIODevice::WriteOnly);
          with this we can write content in file.

          but if we pass string like "\\nas\files\gauravFolder.docx:GauravData:$DATA" its not work.

          Example:-
          QFile file("\\nas\files\gauravFolder.docx:GauravData:$DATA" );
          file.open(QIODevice::WriteOnly);

          with this we can not write content in file. we can not open file.

          please Do needful.

          Regards,
          Gaurav Badgujar.

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 20 Dec 2016, 10:00 last edited by
          #4

          @Gaurav-Badgujar You should not use : in paths/file names especially on Windows

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply 20 Dec 2016, 10:08
          2
          • J jsulm
            20 Dec 2016, 10:00

            @Gaurav-Badgujar You should not use : in paths/file names especially on Windows

            G Offline
            G Offline
            Gaurav Badgujar
            wrote on 20 Dec 2016, 10:08 last edited by
            #5

            @jsulm
            but its working on "D:\TestFoldler:GauravData:$DATA"
            but this is not working with "\nas\files\gauravFolder:GauravData:$DATA" path.

            J 1 Reply Last reply 20 Dec 2016, 10:12
            0
            • G Gaurav Badgujar
              20 Dec 2016, 10:08

              @jsulm
              but its working on "D:\TestFoldler:GauravData:$DATA"
              but this is not working with "\nas\files\gauravFolder:GauravData:$DATA" path.

              J Online
              J Online
              jsulm
              Lifetime Qt Champion
              wrote on 20 Dec 2016, 10:12 last edited by jsulm
              #6

              @Gaurav-Badgujar As others said you should either use \\ or /

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 1 Reply Last reply 20 Dec 2016, 11:57
              1
              • J jsulm
                20 Dec 2016, 10:12

                @Gaurav-Badgujar As others said you should either use \\ or /

                G Offline
                G Offline
                Gaurav Badgujar
                wrote on 20 Dec 2016, 11:57 last edited by
                #7

                @jsulm used "/" as per above mention comment but still not getting any resolution.

                M J 2 Replies Last reply 20 Dec 2016, 12:02
                0
                • G Gaurav Badgujar
                  20 Dec 2016, 11:57

                  @jsulm used "/" as per above mention comment but still not getting any resolution.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 20 Dec 2016, 12:02 last edited by
                  #8

                  @Gaurav-Badgujar
                  Hi
                  Try to use a full path and see it it works for you.
                  "c:/nas/files/gauravFolder:GauravData:$DATA"
                  else
                  "./nas/files/gauravFolder:GauravData:$DATA"
                  Its just path issue, i think.

                  Also again, if on window, the ":" is FORBIDDEN

                  1 Reply Last reply
                  1
                  • G Gaurav Badgujar
                    20 Dec 2016, 11:57

                    @jsulm used "/" as per above mention comment but still not getting any resolution.

                    J Online
                    J Online
                    jsulm
                    Lifetime Qt Champion
                    wrote on 20 Dec 2016, 12:03 last edited by
                    #9

                    @Gaurav-Badgujar What about \\? What exact error do you get (http://doc.qt.io/qt-5/qiodevice.html#errorString)?
                    And why do you use characters like : and $ ? You should avoid such characters in paths and file names. Especially :
                    : has a special meaning on Windows. Try to save a file in any Windows program using file name with : You will see it does not work.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 20 Dec 2016, 12:10 last edited by
                      #10

                      Another option, given the name of the first folder is nas i can guess it's a network path, they normally start with 2 slashes, not just 1

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      G 1 Reply Last reply 20 Dec 2016, 13:13
                      0
                      • M Offline
                        M Offline
                        m.sue
                        wrote on 20 Dec 2016, 12:22 last edited by m.sue
                        #11

                        Hi,
                        the file names with ":" hide data using ADS (alternate data streams). Strings like ":$DATA" have a special meaning. Normal Explorer and DIR command etc. do not see these files.

                        So I doubt Qt can open them for reading/writing; native CreateFile should be able to do so.

                        On the other hand: make sure that the file "c:/nas/files/gauravFolder" already exist when you create the data stream file! Here is some code: https://support.microsoft.com/en-us/kb/105763
                        -Michael.

                        1 Reply Last reply
                        1
                        • B Offline
                          B Offline
                          Buckwheat
                          wrote on 20 Dec 2016, 13:04 last edited by
                          #12

                          @Gaurav-Badgujar ...

                          There are several things wrong with the path but the :$DATA is the biggest hurdle. It is just not allowed on any M$ operating system. Fixing non-existant paths will be easy but if your file name has special meaning then that could be a problem. Now, if the :$DATA represents some bit of data to write into the file name than ok.

                          The article "Illegal Characters on Various Operating Systems" explains what is legal on most OSes.
                          https://kb.acronis.com/content/39790

                          Dave Fileccia

                          1 Reply Last reply
                          0
                          • V VRonin
                            20 Dec 2016, 12:10

                            Another option, given the name of the first folder is nas i can guess it's a network path, they normally start with 2 slashes, not just 1

                            G Offline
                            G Offline
                            Gaurav Badgujar
                            wrote on 20 Dec 2016, 13:13 last edited by
                            #13

                            @VRonin yes its network path..typo mistake. and it contains two slashes.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              Gaurav Badgujar
                              wrote on 20 Dec 2016, 13:21 last edited by
                              #14

                              :$DATA its not a path we append this string with path.

                              1 Reply Last reply
                              0

                              7/14

                              20 Dec 2016, 11:57

                              • Login

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