2

I have develop a small application that uses a SQLite database. Now, I want to create and store this database in user space (in terms of hard disk) in the same way I store settings with QSettings.

I can use QDir and similar classes to find where the user home is, but I want to avoid hidden directories creation, I am looking for a transparent solution and operating system independent.

Can I use the Qt Resources System to create the database into the user home (and find it later)?

How can I make it easy?

1 Answer 1

1

To really answer your question, we need to know a few things. First, how do you want to actually store the DB on disk? Does it need to be in a specific file format? binary? .txt file? .txt/sql file that can be read into another database program (i.e. commands in SQL to rebuild the DBs and tables)?

Qt has an array of objects available to you to store the DB. You can use QFile and QTextStream/QDataStream to create your own custom file. The QDir and QFileDialog classes are excellent supports for this, as far as user interaction goes.

Sign up to request clarification or add additional context in comments.

2 Comments

Why do you need such things (IMHO it does not provide nothing useful to the question)? Currently, the application uses a SQLite database, if it does not exists, the own app code create one and populate it with the appropriate tables. The database is been stored into the same directory as the application, I want to store it in a user directory, as if a QSettings file it was, avoiding the use of QDir and QFileDialog because I am not asking the user for a place or a name for the file
Ok, so don't use QDir and QFileDialog. Pick your own location and hard code it into the program. But how does the format of your file not have anything to do with you saving the DB to disk? If you really want to be abusive of QSettings, you could just force each entry in your DB into QSettings and store that way. Otherwise, you'll need to write a file somewhere to the hard disk which is what I was talking about in my original answer. Your call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.