How can we get the current working directory path ?



  • I have tried
    @QDir::currentpath()@
    but here i am getting the path of current application directory. I want to get path of current working project.



  • Please define "current working project", I don't know what you mean.



  • [quote author="Scylla" date="1331707050"]Please define "current working project", I don't know what you mean.[/quote]

    Suppose the project i am currently running under Qt is "mainwindow". The mainwindow project is present in path "C:/Documents and setting/ Desktop / mainwindow". So i want to get this path.While i am using QDir::currentpath() i am getting "C:/Documents and setting/ Desktop /mainwindow/mainwindow.app/Contents/MacOS" as current path in MAC for that project. which is actually the application path not the current project path. So how could i get the only project path?



  • I don't think this is possible without passing any additional information, as the resulting binary has no information about the origin project structure.
    @
    // .pro

    DEFINES += PROJECT_PATH="\"$$PWD\""
    DEFINES += BUILD_PATH="\"$$OUT_PWD\""

    // .cpp

    QString projectPath(PROJECT_PATH);
    QString buildPath(BUILD_PATH);
    @



  • [quote author="Lukas Geyer" date="1331710589"]I don't think this is possible without passing any additional information, as the resulting binary has no information about the origin project structure.
    @
    // .pro

    DEFINES += PROJECT_PATH="\"$$PWD\""
    DEFINES += BUILD_PATH="\"$$OUT_PWD\""

    // .cpp

    QString projectPath(PROJECT_PATH);
    QString buildPath(BUILD_PATH);
    @[/quote]
    thanks, this i was trying to get.



  • Note that this is then hard coded into your binairy at compile time. Not sure if that is what you expect when you distribute your application...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.