Hello everyone
I'm working on a program and I'm stuck on something I do not understand. I would like the user to create his own database SQLITE (SQLITE: All his information in a file without server) by clicking on a button (bttncreate in the code) but I do not know how to write the code for that.
Here is a picture of the table and the headers..
cenesimple.jpg

Some details to understand the code.
One button: bttncreate
A SQLITE database connected to the table at the top.

Here are the codes
Fencene.h
Qt Code:
  1. #include <QObject>
  2. #include <QWidget>
  3. #include <QGridLayout>
  4. #include <QComboBox>
  5. #include <QPushButton>
  6. #include <QFormLayout>
  7. #include <QTextEdit>
  8. #include <QSpinBox>
  9. #include <QGroupBox>
  10. #include <QRadioButton>
  11. #include <QtSql/QSqlDatabase>
  12. #include <QMessageBox>
  13. #include <QtSql/QSqlTableModel>
  14.  
  15. namespace Ui {
  16. class FenCene;
  17. }
  18.  
  19. class FenCene : public QWidget
  20. {
  21. Q_OBJECT
  22.  
  23. public:
  24. explicit FenCene(QWidget *parent = nullptr);
  25. ~FenCene();
  26.  
  27. private:
  28. Ui::FenCene *ui;
  29. QSqlDatabase *db; //for my database.
  30. QSqlTableModel *model; //join table and database
  31. QPushButton* bttoncreate;
  32.  
  33.  
  34. private slots:
  35. void newfiledb();
  36.  
  37. };
  38.  
  39. #endif // FENCENE_H
To copy to clipboard, switch view to plain text mode 

Fencene.cpp

Qt Code:
  1. #include "fencene.h"
  2. #include "ui_fencene.h"
  3.  
  4.  
  5. FenCene::FenCene(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::FenCene)
  8. {
  9. ui->setupUi(this);
  10. bttoncreate = new QPushButton("Cahier Electronique de Note de L'Enseignant Principal (CEN_EP)");
  11. bttoncreate->setFont(QFont("Times New Roman", 20));
  12. bttoncreate->setCursor(Qt::PointingHandCursor);
  13. connect(bttoncreate, &QPushButton::clicked, this, &FenCene::newfiledb);
  14. }
  15.  
  16.  
  17. FenCene::~FenCene()
  18. {
  19. delete ui;
  20. }
  21.  
  22. void FenCene::newfiledb() // SLot no connected....
  23. {
  24. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  25. db.setDatabaseName("......"); //Each User give an name at database
  26. db.setHostName("local"); //i don't know if it's necessary
  27.  
  28. if(!db.open())
  29. {
  30. QMessageBox::critical(0, qApp->tr("Cannot open database"),
  31. qApp->tr("La connexion n'est pas correctement établis à la base de donnée"
  32. "Reprenez le processus.\n\n"
  33. "Cliquer sur annuler pour quitter");
  34. return false ; //i don't know if it's necessary
  35. }
  36.  
  37. QSqlQuery query; //Student Only
  38. query.exec("create table student (ID int, "
  39. "Nomprenoms varchar(100), "
  40. "DateDeNaissance varchar(20), "
  41. "Sexe varcher (1)"
  42. "Varchar(20), "
  43. "matiere(20),"
  44. "notei1 int, "
  45. "notei2 int, "
  46. "notei3 int, "
  47. "notei4 int, "
  48. "notei5 int, "
  49. "noted1 int, "
  50. "noted2 int, "
  51. "Comment bool (15)))"); // I did not put Moy Interro, Moy Sem and Moy Coef into the database.
  52.  
  53.  
  54. //table student + table class + Table subject + table note = student record
  55.  
  56.  
  57. model = new QSqlTableModel;
  58. model->setTable("Student");
  59. model->setEditStrategy(QSqlTableModel::OnFieldChange);
  60. model->select();
  61.  
  62. model->removeColumn(0);
  63. model->setHeaderData(0, Qt::Horizontal, "Nom(s) & Prénom(s)");
  64. model->setHeaderData(1, Qt::Horizontal, "Sexe");
  65. model->setHeaderData(2, Qt::Horizontal, "Statut");
  66. model->setHeaderData(3, Qt::Horizontal, "Coef");
  67. model->setHeaderData(4, Qt::Horizontal, "1è");
  68. model->setHeaderData(5, Qt::Horizontal, "2è");
  69. model->setHeaderData(6, Qt::Horizontal, "3è");
  70. model->setHeaderData(7, Qt::Horizontal, "4è");
  71. model->setHeaderData(8, Qt::Horizontal, "5è");
  72. model->setHeaderData(9, Qt::Horizontal, "Moy Interro"); //No Include in database
  73. model->setHeaderData(10, Qt::Horizontal, "1è");
  74. model->setHeaderData(11, Qt::Horizontal, "2è");
  75. model->setHeaderData(12, Qt::Horizontal, "Moy Sem"); // No Include in database
  76. model->setHeaderData(13, Qt::Horizontal, "Moy Coef"); // No Include in database
  77. model->setHeaderData(14, Qt::Horizontal, "Mentions");
  78.  
  79. QTableView *view = new QTableView;
  80. view->setModel(model);
  81.  
  82. v->addWidget(view);
  83. return true;
  84. }
To copy to clipboard, switch view to plain text mode 

Please help me for the coding. I am available for all questions.
Thank you in advance