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. [Solved] Double click does not read ini file
Forum Updated to NodeBB v4.3 + New Features

[Solved] Double click does not read ini file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.6k 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.
  • N Offline
    N Offline
    ninio
    wrote on last edited by
    #1

    Here an extrange problem:
    If I run the executable from Qt Creator or console, the ini file is read correctly. But if I run by double click the executable from the folder, it does not.

    I'm on Linux, KDE.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You are probably using a relative path to an INI file and the current working directory of the executable is different in the different environments.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ninio
        wrote on last edited by
        #3

        Nope sir, I'm using the same path and the problem is in the same environment. It works running from Qt Creator, then I open the folder and give double click on the executable and doesn't read the ini file.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          viktor.benei
          wrote on last edited by
          #4

          But does the executable start with 'double click' properly and it just doesn't read the ini file? In this case I would suggest you to log the ini file's path to a file and check whether the path is correct.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            ninio
            wrote on last edited by
            #5

            Good!, now I cant see:

            Running from Qt Creator or console: Path is right

            Running by double clicking: Path is /home/user/ini_file

            The ini file must be read from the relative path, which is the application's path. How can I solve? :S

            1 Reply Last reply
            0
            • V Offline
              V Offline
              viktor.benei
              wrote on last edited by
              #6

              If you use relative paths it's always relative to the application's working directory. The working directory is by default the one you start the app from. So if you start it from terminal/command line it will be the directory you're in when you issue the 'execute' command.

              If you want to use your application's executable path you can get it with QCoreApplication::applicationDirPath()

              "If you want to find the directory containing the application's executable, see QCoreApplication::applicationDirPath()"
              http://doc.qt.nokia.com/4.7-snapshot/qdir.html

              But for this you have to know where your executable really is. For example on Windows it's the .exe you execute with a double-click. On the other hand on Mac the executable is not the .app what users consider as the executable, but the real executable somewhere in the .app

              It's a consistent solution but you have to know these differences between the operating systems - if you plan to distribute to multiple operating systems.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                ninio
                wrote on last edited by
                #7

                Excellent!, I just solved this issue using QCoreApplication::applicationDirPath().

                Thank you sooo much viktor.benei :)

                1 Reply Last reply
                0

                • Login

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