Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [SOLVED] using the prefix in a resource file

    General and Desktop
    5
    14
    7722
    Loading More Posts
    • 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.
    • X
      xeroblast last edited by

      using QDir::homePath() display the path of home directory for every user.

      how do i put a prefix in the resource file using the home directory of the user?

      unix: /home/username
      windows: c:\Documents and Settings\username

      thanx.

      1 Reply Last reply Reply Quote 0
      • F
        Franzk last edited by

        You don't. The files you use are encoded into a cpp file resulting from the rcc tool. They are then compiled into your program. The prefix is used for making (logical) separations between groups of images/whatever.

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

        1 Reply Last reply Reply Quote 0
        • X
          xeroblast last edited by

          so i have to use :

          @
          QUrl url("path/to/file");
          QDir::homePath() + url.toLocalFile();
          @

          1 Reply Last reply Reply Quote 0
          • G
            giesbert last edited by

            What exactly do you want to achieve?

            Access to resources is done this way:

            QFile f (":/myPrefix/mySubprefeix/name");
            the ":" in the beginning tells qt to use the resources.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply Reply Quote 0
            • F
              Franzk last edited by

              If you want to load an image from a certain location, use QDir::homePath(), QUrl or whatever is required (QFileDialog, QDesktopServices). If you need an image in your resource file, use the resource editor to add it and let Qt handle it. You don't need access to the home dir then.

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

              1 Reply Last reply Reply Quote 0
              • X
                xeroblast last edited by

                im putting configuration files in the home directory.
                the QFile cant read the file unless i put the file in the current folder.

                unix: /home/username/.myapp/files.ext
                windows: c:\Documents and Settings\username\Application Data\myapp\files.ext

                1 Reply Last reply Reply Quote 0
                • F
                  Franzk last edited by

                  On both platforms?
                  Why not use QSettings?

                  "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

                  1 Reply Last reply Reply Quote 0
                  • A
                    andre last edited by

                    In that case, you should look into the QDesktopServices class. It will supply you with a cross platform way to query for locations on disk like this. In your case, you are probably looking for QDesktopServices::DataLocation.

                    Note that inside your Qt program, you should use forward slashes for all file paths, even on Windows. Only for paths you display to the user, you can use QDir::toNativeSeparators to get the native format.

                    1 Reply Last reply Reply Quote 0
                    • X
                      xeroblast last edited by

                      Franzk: i cant use QSettings cause i need to save the configurations to a file so i could load it again using the QFile then use QSettings.

                      Andre: i think ill try QDesktopServices::DataLocation. it seems that this directory is where my configurations files to be stored.

                      1 Reply Last reply Reply Quote 0
                      • F
                        Franzk last edited by

                        [quote author="xeroblast" date="1299583686"]Franzk: i cant use QSettings cause i need to save the configurations to a file so i could load it again using the QFile then use QSettings.[/quote]

                        QSettings can do ini files. You just have to explicitly tell it to do that on windows. On linux the settings are stored in ~/.config/.

                        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

                        1 Reply Last reply Reply Quote 0
                        • X
                          xeroblast last edited by

                          [quote author="Franzk" date="1299585456"]QSettings can do ini files. You just have to explicitly tell it to do that on windows. On linux the settings are stored in ~/.config/.[/quote]

                          ok. i think this is what i want. i just didnt know where the ini files located. i thought QSettings didnt saved it.

                          so in windows, where is the ini files located?

                          1 Reply Last reply Reply Quote 0
                          • F
                            Franzk last edited by

                            It saves them where you tell it to save them. By default it will go for registry, but there's the option of setting the format and file: http://doc.trolltech.com/latest/qsettings.html#QSettings-4

                            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

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

                            1 Reply Last reply Reply Quote 0
                            • X
                              xeroblast last edited by

                              thanks for the info...

                              1 Reply Last reply Reply Quote 0
                              • S
                                shadow.seeker last edited by

                                Resolved mine also. thanks again.
                                Can there be a small an example put in the list also. Would help lot as most of us spend loads of time searching it.

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post