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 to programmatically determine the project folder name?

How to programmatically determine the project folder name?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 955 Views
  • 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.
  • vrcmr 0V Offline
    vrcmr 0V Offline
    vrcmr 0
    wrote on last edited by
    #1

    Use a project wizard.

    1. New Project
    2. EnterName > SimpleApp > Create in > /home/user/qtprojects

    Now try to print project folder name.

    main.cpp

    ...
    qDebug << someStandartFunctionToGetProjectFolderName() << ;
    ...
    

    Output should be: SimpleApp

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

      Hi and welcome to devnet,

      Why do you need that information ?

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

      vrcmr 0V 1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        This may not be the short answer but:
        1 add this to your profile:

        `DEFINES += MYPROJDIR=$$_PRO_FILE_PWD_
        ``
        2. code should be something like:
        

        #define xstr(s) str(s)
        #define str(s) #s

        int main(int argc, char *argv[])
        {
        QCoreApplication a(argc, argv);
        QString projdir = QString(xstr(MYPROJDIR));
        qDebug() << "Source Directory = " << projdir;
        return a.exec();
        }

        vrcmr 0V 1 Reply Last reply
        3
        • SGaistS SGaist

          Hi and welcome to devnet,

          Why do you need that information ?

          vrcmr 0V Offline
          vrcmr 0V Offline
          vrcmr 0
          wrote on last edited by
          #4

          @SGaist just a quiz :)

          1 Reply Last reply
          0
          • mranger90M mranger90

            This may not be the short answer but:
            1 add this to your profile:

            `DEFINES += MYPROJDIR=$$_PRO_FILE_PWD_
            ``
            2. code should be something like:
            

            #define xstr(s) str(s)
            #define str(s) #s

            int main(int argc, char *argv[])
            {
            QCoreApplication a(argc, argv);
            QString projdir = QString(xstr(MYPROJDIR));
            qDebug() << "Source Directory = " << projdir;
            return a.exec();
            }

            vrcmr 0V Offline
            vrcmr 0V Offline
            vrcmr 0
            wrote on last edited by vrcmr 0
            #5

            @mranger90 that is an interesting solution. Thank you. However it depends on qmake which is "deprecated" according to this blog post.

            "Longer term, we plan to switch to CMake for building Qt itself"

            K 1 Reply Last reply
            0
            • mranger90M Offline
              mranger90M Offline
              mranger90
              wrote on last edited by
              #6

              I wouldnt worry to much about QMake being deprecated. Its going to be around for a while.
              The point of it is to pass the current directory as a define -D to the compiler. Its just as easily done in CMake or the command line,
              The hard part is getting the quote pasting correct.

              1 Reply Last reply
              2
              • vrcmr 0V vrcmr 0

                @mranger90 that is an interesting solution. Thank you. However it depends on qmake which is "deprecated" according to this blog post.

                "Longer term, we plan to switch to CMake for building Qt itself"

                K Offline
                K Offline
                kenchan
                wrote on last edited by
                #7

                @vrcmr-0 said in How to programmatically determine the project folder name?:

                this

                Where in that link does it say qmake will be deprecated? It is talking about deprecating Qbs!!

                vrcmr 0V 1 Reply Last reply
                2
                • K kenchan

                  @vrcmr-0 said in How to programmatically determine the project folder name?:

                  this

                  Where in that link does it say qmake will be deprecated? It is talking about deprecating Qbs!!

                  vrcmr 0V Offline
                  vrcmr 0V Offline
                  vrcmr 0
                  wrote on last edited by
                  #8

                  @kenchan Thats why I use quotation marks for. "deprecated" I mean not realy. maybe :)

                  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