Re: Sqlite3 window problem
on windows Qt also creates file with databasename in app directory.
but if you this like this
Code:
db.setDatabaseName(":memory:");
then the database will be allocated in memory.
Re: Sqlite3 window problem
I did not.
Code:
d.setDatabaseName(databaseName);
Still, I cannot see the file in the any folder, but I can do sql query!
How is it possible?
even if I close the application the database file is not present....
:confused:
Re: Sqlite3 window problem
did you change work directory (dest dir) in pro-file?
Re: Sqlite3 window problem
I don't know what you are talking about....
Please, shine me!
Re: Sqlite3 window problem
ok, build an troll's example. go to QTDIR/examples/sql and in connection.h change the next lines
Code:
// db.setDatabaseName(":memory:");
db.setDatabaseName("test.db");
then go (for example) to cachedtable dir, build and run this example. the "test.db" file should be with executable file.
Re: Sqlite3 window problem
I still do not understand.
My exec is in debug folder.
If I try to create a database e.g. d.setDatabaseName("pinco.db"), the database FILE is correctly created in the debug folder.
BUT: If i try to create d.setDatabaseName("C:/Docuemnts and Settings/giuse") the file IS NOT CREATED, but I can make queries!
G
Re: Sqlite3 window problem
I've tried to connect to a database with name wich you specified and a file was created.
Re: Sqlite3 window problem
You are under windows?
The same code under linux works (the file is created). But in windows not.
I am desperate.
Anyway, a solution is to close the connection, reopen it with addDatabase.
In this case the file is created.
G
Re: Sqlite3 window problem
I'm under windos now and a file creates fine. which version of Qt do you use? maybe this is a bug. I use 4.3.5.
Re: Sqlite3 window problem
I did not want to post the code, but I am really confused.
Actually, the error is present in linux too.
In my mainwindow constructor I did
Code:
mainWindow::manWindow(
....
if (createConnection())
{
initializeModel();
createView();
....
}
}
and
Code:
bool mainWindow::createConnection()
{
/* If the database do not exist
I create one anew*/
check.setFileName(databaseName);
db.setDatabaseName(databaseName);
if (!check.exists()){
#ifdef DEBUG
qDebug()<<databaseName<<"do not exist. However, is open="<<db.open();
#endif
currentDatabase = databaseName ;
createTable();
statusLabel->setText(currentDatabase);
}
if (!db.open()) {
#ifdef DEBUG
qDebug()<<db.lastError()<<db.open();
#endif
removeConnection();
return false;
}
When I wanna add a new datatabase (which in SQLITE means a new file!) I do
Code:
void mainWindow::newDB()
{
/* Create a new archive*/
QString fileName
= QFileDialog::getSaveFileName(this, tr
("Nuovo archivio"),
QDir::homePath (),tr
("Rubic database (*.db)"));
if (fileName != currentDatabase)
{
db.setDatabaseName(fileName);
#ifdef DEBUG
qDebug()<<"newDB, opening"<<db.lastError()<<"is open="<<db.isOpen()<<fileName<<db.isValid();
#endif
if (db.isValid()){
currentDatabase = fileName;
createTable();
initializeModel();
createView();
statusLabel->setText(currentDatabase);
}
}
}
currentDatabase = databaseName;
return true;
}
The funny think is
1) After the start up, If I create a newDB, the debug messages say that the database has been created. IN fact I can use the queries but I cannot see any database file in the choosen dir
2) If I quit the application, since a write the currentDatabase var. inside a QSettings, the debu message says that the database does not exist and it will create it.
3) The only way I found to let it work is to addDatabase also in the newDB function.
Any suggestion appreciated
Re: Sqlite3 window problem
I found a solution but I do not understand why it is working.
First I create a static member function in mainWindow:
Code:
bool mainWindow::createConnStatic()
{
}
which is declared static in the header file.
Now, at the startup I create a connection by calling this function. db is a member variable.
When I wann change database, I do
Code:
db.setDatabaseName(s);
This work pretty well, but is "impossible" to got there by reading the Qt Doc.