Hi, i'm programming a simple sqlite manager in qt.
All is working, just the fact that the QTableView i use, doesn't paint correctly where i positioned it in the designer, instead, it obscure all the menu, and i can't access it, and this is not good, obviously.
Data is loaded correctly when i open the database file.
I attach i file to let you see what is the situation.
How i can fix it ?
I also post the source code:
The Constructor
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
FiereMainWindow::FiereMainWindow(QWidget *parent) : QMainWindow(parent),
ui(new Ui::FiereMainWindow),
defaultDatabaseName("fiere.db") {
ui->setupUi(this);
sqliteDatabase = QSqlDatabase::addDatabase("QSQLITE");
sqlTableModel = new QSqlTableModel(this, sqliteDatabase);
sqlTableModel->setEditStrategy(QSqlTableModel::OnFieldChange);
databaseTableView = new QTableView(this);
databaseTableView->setModel(sqlTableModel);
databaseTableView->setFixedHeight(500);
databaseTableView->setFixedWidth(500);
if(!openSqliteDatabase((QString&)defaultDatabaseName)) {
statusBar()->showMessage(tr("File Database non aperto, errore."));
}
}
|
The open function
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
bool FiereMainWindow::openSqliteDatabase(QString& path) { const char* databaseTableUtenteFields[] = {
"id" ,
"nome" ,
"cognome" ,
"nazione" ,
"fiera_id" ,
"anno" ,
"indirizzo",
"citta" ,
"code" ,
"email" ,
"importo"
};
QString prova;
QString fileNotFound_ErrorMessage = tr("Impossibile aprire il file ") + path + tr(": il file non esiste o c'è stato qualche altro problema. Verificare la presenza del file nel sistema, il path, la cartella, la configurazione e quanto può essere possibile per risolvere il problema");
if(!QFile::exists(path)) {
QMessageBox::warning(this, tr("Warning"), fileNotFound_ErrorMessage, QMessageBox::Ok);
return false;
}
sqliteDatabase.setDatabaseName(path);
if(!sqliteDatabase.open()) {
QMessageBox::warning(this, tr("Warning"), tr("Errore durante l'apertura del database") + sqliteDatabase.lastError().databaseText(), QMessageBox::Ok);
return false;
}
sqlTableModel->setTable("UTENTE");
for(unsigned int i = 0; i < sizeof(databaseTableUtenteFields) / sizeof(databaseTableUtenteFields[0]); i++) {
sqlTableModel->setHeaderData(i, Qt::Horizontal, tr(databaseTableUtenteFields[i]));
prova += databaseTableUtenteFields[i];
prova += "\n";
}
qDebug(qPrintable(prova));
sqlTableModel->select();
sqlTableModel->submitAll();
statusBar()->showMessage(tr("File Database aperto, all is good."));
return true;
}
|
And that's it.
If you need something else, just ask.
I'm running QtCreator 2.1.0, with Qt 4.7.1, on Windows 7 Home Premium machine.
Thank you in advance,
Marco.