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. How do i code this right (Linux Only)
Forum Updated to NodeBB v4.3 + New Features

How do i code this right (Linux Only)

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 2.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.
  • M Offline
    M Offline
    MathSquare
    wrote on last edited by
    #1

    @
    QDir dir("~/.MyProject");

    if (!dir.exists()) {
    
        dir.mkpath("~/.MyProject");
    
    }
    

    @
    Doesn't Work or
    @
    QDir dir("$HOME/.MyProject");

    if (!dir.exists()) {
    
        dir.mkpath("$HOME/.MyProject");
    

    @
    But when i do
    @
    QDir dir("/home/myusername/.MyProject");

    if (!dir.exists()) {
    
        dir.mkpath("$/home/myusername/.MyProject");
    

    @
    it does work but it will only work for me and not other that i want to give my proect way to becuase it have my username not there so i can i fix it. :(

    [[Marked up code and moved this out of the experimental QnA area, Tobias]]

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

      You can get value of HOME variable using "getenv":http://www.cplusplus.com/reference/cstdlib/getenv/

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MathSquare
        wrote on last edited by
        #3

        I Found a way

        @
        QString UserHomeDir = (getenv("HOME"));
        QString MyProjectDirExtension = ("/.MyProject");
        QString MyProjectDir = (UserHomeDir + MyProjectDirExtension);
        @

        [[marked up more code, Tobias]]

        1 Reply Last reply
        0
        • L Offline
          L Offline
          luca
          wrote on last edited by
          #4

          What about:
          @
          QDir::homePath()
          @
          ?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            There is a reason why this section is called "QnA Testing Area": This is an experimental feature which may or may not survive.

            Please do not use it for real questions.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Fahmy
              wrote on last edited by
              #6

              Just use QDesktopServices::storageLocation(QDesktopServices::HomeLocation);

              Stay hungry, stay foolish.

              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