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. Only when I start from QtCreator program works fine / read write to xml
Forum Updated to NodeBB v4.3 + New Features

Only when I start from QtCreator program works fine / read write to xml

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 4 Posters 1.8k Views 3 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.
  • Allman 2A Offline
    Allman 2A Offline
    Allman 2
    wrote on last edited by Allman 2
    #1

    Hi everbody,

    so I finished my program and when it starts within creator and the run function it
    works fine. But when I start it with a double click from the filesystem it don't read and write in the xml.

    0_1516297069050_Bildschirmfoto 2018-01-18 um 6.37.26 PM.png

    Do you have any ideas.

    THX
    Allman

    1 Reply Last reply
    0
    • Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @Allman-2 you should provide more information regarding your environment, i.e. different folder when you run from IDE than when you double click your executable? In any case, when opening the XML file for reading, you should check for any errors, which may give you a hint of why is not working.

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      Allman 2A 1 Reply Last reply
      1
      • Pablo J. RoginaP Pablo J. Rogina

        @Allman-2 you should provide more information regarding your environment, i.e. different folder when you run from IDE than when you double click your executable? In any case, when opening the XML file for reading, you should check for any errors, which may give you a hint of why is not working.

        Allman 2A Offline
        Allman 2A Offline
        Allman 2
        wrote on last edited by
        #3

        @Pablo-J.-Rogina
        Hey Pablo,
        no it's anytime the same xml-file. and with qt got no error.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          To run it outside Creator, it should have its needed SO files with it.
          try LDD on the ".exe" and see if any So files are missing.

          1 Reply Last reply
          1
          • Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @Allman-2 again, are you implementing some error checking when opening the file? QFile::errorString()

                ...
                QFile xmlFile("/path/to/XMLfile");
            
                if (!xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
                    qDebug() << xmlFile.errorString();
                } else {
                    qDebug() << "It worked";
                }
                ...
            

            and given no file exists for instance, you'll have this handy error message:

            "No such file or directory"
            

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • Allman 2A Offline
              Allman 2A Offline
              Allman 2
              wrote on last edited by
              #6

              Hey,
              so in my pic I attached, you can see that my time stamp of the main.xml is more newer than other filer, thats cause I wrote after creating to it.
              And Pablo yes I'm using that snippet code you pronounced from the qt-api.

              Well I' m thinking it is something with the read and write rights, I will check it out.
              THX

              1 Reply Last reply
              0
              • Allman 2A Offline
                Allman 2A Offline
                Allman 2
                wrote on last edited by Allman 2
                #7

                so to get the correct path ->
                QString current = QDir::currentPath();
                QStringList url = current.split(QFileInfo(QCoreApplication::applicationFilePath()).fileName());
                xmlFile = new QFile(url.at(0)+QString("main.xml"));

                you can find the entire code here:
                here: https://github.com/lustigepepe/TinWeb.git

                in the xmllibrary.cpp line 9 is the reading from the main.xml

                THX

                1 Reply Last reply
                0
                • Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @Allman-2 it looks like you solved your issue. If so, please don't forget to mark your post as such. Thank you.

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  Allman 2A 2 Replies Last reply
                  0
                  • Pablo J. RoginaP Pablo J. Rogina

                    @Allman-2 it looks like you solved your issue. If so, please don't forget to mark your post as such. Thank you.

                    Allman 2A Offline
                    Allman 2A Offline
                    Allman 2
                    wrote on last edited by
                    #9

                    @Pablo-J.-Rogina

                    no, it still doesn't work the permission rights a correct and the code is still the same.

                    1 Reply Last reply
                    0
                    • Pablo J. RoginaP Pablo J. Rogina

                      @Allman-2 it looks like you solved your issue. If so, please don't forget to mark your post as such. Thank you.

                      Allman 2A Offline
                      Allman 2A Offline
                      Allman 2
                      wrote on last edited by
                      #10

                      @Pablo-J.-Rogina

                      here ::
                      this code works fine within creator but not when I double-click it.
                      QString current = QDir::currentPath();
                      QStringList url = current.split(QFileInfo(QCoreApplication::applicationFilePath()).fileName());
                      xmlFile = new QFile(url.at(0)+QString("main.xml"));

                      do you have any idea why?

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Hi,

                        Did you check the content of your QStringList before trying to build the file path ?

                        In any case, expecting the file to be writable when it's located in the same folder as your application is not a good idea. On Windows for example, the Program Files folder is read only. The same goes for *nix system's /bin, /usr/bin and /usr/local/bin.

                        You should rather have a default file embedded within your application that you copy over to best suited place given by QStandardPaths::writableLocation.

                        By the way, you are using pointers way to much in your code and not in the best way. For example, there's no need to allocate QString on the heap. When you need to pass one around, use const references.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        Allman 2A 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          Hi,

                          Did you check the content of your QStringList before trying to build the file path ?

                          In any case, expecting the file to be writable when it's located in the same folder as your application is not a good idea. On Windows for example, the Program Files folder is read only. The same goes for *nix system's /bin, /usr/bin and /usr/local/bin.

                          You should rather have a default file embedded within your application that you copy over to best suited place given by QStandardPaths::writableLocation.

                          By the way, you are using pointers way to much in your code and not in the best way. For example, there's no need to allocate QString on the heap. When you need to pass one around, use const references.

                          Allman 2A Offline
                          Allman 2A Offline
                          Allman 2
                          wrote on last edited by
                          #12

                          @SGaist said in Only when I start from QtCreator program works fine / read write to xml:

                          Program Files
                          mhhh
                          yeahr everyone is scared about pointers but when this variable can be empty, I think
                          pointer is good solution. Ok the heap is more slowly, your right.

                          1 Reply Last reply
                          0
                          • Allman 2A Offline
                            Allman 2A Offline
                            Allman 2
                            wrote on last edited by Allman 2
                            #13

                            @SGaist
                            @Pablo-J-Rogina
                            Well a Big big thanks to all, the solution is :: QCoreApplication::applicationDirPath()
                            instead using QDir::currentPath() !!!
                            AND SGaist thx for the tip with the write location, now it's changed!
                            Big Cheers.!!

                            1 Reply Last reply
                            1

                            • Login

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