0

In my project I have a database, eg Data.db. Using it in my code, I give a constant path / home / adam / cpp / etc .. I would like to use a relative path, how can I do this? in the .pro file? resources?

code:

bool LoginWindow::loginConnect()
{
    loginDatabase = QSqlDatabase::addDatabase("QSQLITE");
    loginDatabase.setDatabaseName("/home/jarek/ProjectInQt/BankManagment-Qt/BankManagment/sql/Login.db");
    return loginDatabase.open() ? true : false;
}

I want relative path to Login.db

Eriss69
  • 69
  • 5
  • 1
    You will need to show some code so we understand what you mean exactly. - That being said, why would you not be able to use a relative path instead of an absolute one in your path constant? Usually paths are relative to the current working directory when executing your executable. – PhilMasteG Jun 05 '22 at 19:16
  • I'll edit a post wait. edit: @PhilMasteG but look, when someone downloads my project they will have to give their paths to the same files from the database – Eriss69 Jun 05 '22 at 19:17
  • Suppose, you use "mydb.db" as database filename. When you place mydb.db in the same directory as the executable and then run the executable when your working path is in the executable folder it will work. Of course, you might want to get the directory of the current executable and then construct an absolute path from that, so that mydb.db is always searched in the same directory as the executable and not the current working path. Is that what you are actually looking for? – PhilMasteG Jun 05 '22 at 19:34
  • @PhilMasteG yes i looking this – Eriss69 Jun 06 '22 at 19:59
  • Then have a look at the answer [here](https://stackoverflow.com/questions/42136068/how-to-determine-the-directory-of-the-executable-file-using-qt) – PhilMasteG Jun 07 '22 at 07:44

0 Answers0