0

I have a sqlite database of my Qt C++ application. Suppose I located it on my default build/release folder and I also placed the database file on that same folder. I have login.h and login.cpp. I want that the application may auto detect the database and open it. I will only provide the name of database (Ex: mydb.sqlite).

Database.addDatabase("QSQLITE");
Database.setDatabaseName("I will only provide database file name here.like: mydb.sqlite");

I want that the rest of the directory should automatically detected and the database connection works perfectly. Suppose, I have the sqlite file in: C:/Qt/build-myapp-mingw-32/mydb.sqlite. I am taking a string variable called path. And I want that, the application automatically detect the whole path. And open the database connection.

  • _The rest should be done by the application it self._ what exactly means _the rest_. – scopchanov Jul 17 '20 at 06:46
  • @scopchanov first of all, i want to thank you for replying. I edited the question. Hope you got it. Please help me if it is possible. Thanks –  Jul 17 '20 at 06:52
  • That does not answer my question. – scopchanov Jul 17 '20 at 06:55
  • @scopchanov I don't know why you don't understanding. I have edited again. Hope you got it this time. :( –  Jul 17 '20 at 06:59
  • So, by _the rest_ you mean the full path, right? Why is this necessary? As long as you have your database file under your build folder (when running your app with QtCreator), the full path does not need to be specified. – scopchanov Jul 17 '20 at 07:19

1 Answers1

-1

You do not have to give the complete path to database to make it works. You can refer to the path from your build dir or maybe use :

QCoreApplication::applicationDirPath();

To get the path of your app and then navigate through your directories with .. ?

Dharman
  • 30,962
  • 25
  • 85
  • 135