Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't write into database
Forum Updated to NodeBB v4.3 + New Features

Can't write into database

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqldatabaseqsqlqml
14 Posts 2 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Babs
    5 Mar 2020, 16:11

    @artwaw thanks you. I moved my database and tableCreation in my main function. I assume that it's called only once then. It still doesn't work. By printing lastError().txt i get the following message:
    SqlQuery::prepare: database not open
    "Driver not loaded Driver not loaded"

    A Offline
    A Offline
    artwaw
    wrote on 5 Mar 2020, 16:16 last edited by
    #4

    @Babs Ok. So now you can test db.open() - it returns a value. On false, error should be present in lastError().

    For more information please re-read.

    Kind Regards,
    Artur

    B 1 Reply Last reply 5 Mar 2020, 16:21
    0
    • A artwaw
      5 Mar 2020, 16:16

      @Babs Ok. So now you can test db.open() - it returns a value. On false, error should be present in lastError().

      B Offline
      B Offline
      Babs
      wrote on 5 Mar 2020, 16:21 last edited by Babs 3 May 2020, 16:22
      #5

      @artwaw it returns false and the error driver not loaded. I do the verification:

              if(!db.isOpen()){
                  db.open();
                  qDebug()<<db.lastError().text();
              }
      
      A 1 Reply Last reply 5 Mar 2020, 16:25
      0
      • B Babs
        5 Mar 2020, 16:21

        @artwaw it returns false and the error driver not loaded. I do the verification:

                if(!db.isOpen()){
                    db.open();
                    qDebug()<<db.lastError().text();
                }
        
        A Offline
        A Offline
        artwaw
        wrote on 5 Mar 2020, 16:25 last edited by
        #6

        @Babs Are you completely sure that addDatabase() has been called at any point before call do QSqlDatabase::database()?
        You could also test if driver is available by using QSqlDatabase::drivers() and other methods described in documentation.

        For more information please re-read.

        Kind Regards,
        Artur

        B 2 Replies Last reply 5 Mar 2020, 16:27
        0
        • A artwaw
          5 Mar 2020, 16:25

          @Babs Are you completely sure that addDatabase() has been called at any point before call do QSqlDatabase::database()?
          You could also test if driver is available by using QSqlDatabase::drivers() and other methods described in documentation.

          B Offline
          B Offline
          Babs
          wrote on 5 Mar 2020, 16:27 last edited by
          #7

          @artwaw do i have to specify the connectionName when calling database() function?. Add data base in called in my main function before creation my engine.

          1 Reply Last reply
          0
          • A artwaw
            5 Mar 2020, 16:25

            @Babs Are you completely sure that addDatabase() has been called at any point before call do QSqlDatabase::database()?
            You could also test if driver is available by using QSqlDatabase::drivers() and other methods described in documentation.

            B Offline
            B Offline
            Babs
            wrote on 5 Mar 2020, 16:30 last edited by
            #8

            @artwaw the driver for SQLite is indeed present.

            A 1 Reply Last reply 5 Mar 2020, 16:30
            0
            • B Babs
              5 Mar 2020, 16:30

              @artwaw the driver for SQLite is indeed present.

              A Offline
              A Offline
              artwaw
              wrote on 5 Mar 2020, 16:30 last edited by
              #9

              @Babs can you post your .pro files please?

              For more information please re-read.

              Kind Regards,
              Artur

              B 2 Replies Last reply 5 Mar 2020, 16:47
              0
              • A artwaw
                5 Mar 2020, 16:30

                @Babs can you post your .pro files please?

                B Offline
                B Offline
                Babs
                wrote on 5 Mar 2020, 16:47 last edited by
                #10

                @artwaw i'm working with QBS. When i don't specify the connectionName in addDataBase() function it open. I have the error "number of parameters incorrect". I think i don't have the good parameter types. I defined a QString as a TEXT is SQLite. Is it correct?

                1 Reply Last reply
                0
                • A artwaw
                  5 Mar 2020, 16:30

                  @Babs can you post your .pro files please?

                  B Offline
                  B Offline
                  Babs
                  wrote on 5 Mar 2020, 16:47 last edited by
                  #11

                  @artwaw here is my QBS file

                  import qbs
                  
                  
                  
                  Project{
                      name: "PlanningModrian"
                  
                      Product{
                          files: [
                          ]
                          name: ( "modrian");
                          type: "application";
                          targetName: (project.targetPrefixTools + "modrian");
                          cpp.dynamicLibraries: {
                              var ret = [];
                              if (Qt.core.versionMinor < 4) { // NOTE : prior to Qt5.4 we had to link libGL manually
                                  ret.push ("GL");
                              }
                              return ret;
                          }
                  
                          cpp.cxxLanguageVersion: "c++14"
                          readonly property stringList qmlImportPaths : [sourceDirectory + "/import"]; // equivalent to QML_IMPORT_PATH += $$PWD/import
                  
                          Depends { name: "Qt.quick" }
                          Depends {
                              name: "Qt";
                              submodules: ["core", "gui", "qml", "quick","testlib","sql"];
                          }
                          Group{
                              name: "C++ sources";
                              files: [
                                  "planning.cpp",
                                  "main.cpp",
                                  "admin.cpp",
                                  "testPlanning.cpp",
                                  "user.cpp",
                                  "equipement.cpp",
                                  "equimenttablemodel.cpp",
                                  "palier.cpp",
                                  "paliermodel.cpp",
                                  "appwrapper.cpp",
                              ]
                          }
                          Group {
                              qbs.install: (product.type === "dynamiclibrary");
                              fileTagsFilter: product.type;
                          }
                  
                          Group{
                              name: "C++ headers";
                              files: [
                                  "admin.h",
                                  "appwrapper.h",
                                  "datetimevalidator.cpp",
                                  "datetimevalidator.h",
                                  "equimenttablemodel.h",
                                  "manager.cpp",
                                  "manager.h",
                                  "paliermodel.h",
                                  "planning.h",
                                  "user.h",
                                  "equipement.h",
                                  "palier.h",
                              ]
                          }
                          Group  {
                              name: "QML files"
                              files: [
                                  "DatePicker.qml",
                                  "DateUtils.js",
                                  "Planning.qml",
                                  "main.qml",
                                  "PagePlannification.qml",
                                  "qml.qrc",
                              ]
                          }
                  
                          //Depends { name: (project.namePrefixBase + "utils"); }
                          Depends { name: "libqtqmltricks-qtsupermacros"; }
                          Depends { name: "libqtqmltricks-qtqmlmodels"; }
                          Depends { name: "libqtqmltricks-qtquickuielements"; }
                      }
                  }
                  
                  
                  A B 2 Replies Last reply 5 Mar 2020, 16:55
                  0
                  • B Babs
                    5 Mar 2020, 16:47

                    @artwaw here is my QBS file

                    import qbs
                    
                    
                    
                    Project{
                        name: "PlanningModrian"
                    
                        Product{
                            files: [
                            ]
                            name: ( "modrian");
                            type: "application";
                            targetName: (project.targetPrefixTools + "modrian");
                            cpp.dynamicLibraries: {
                                var ret = [];
                                if (Qt.core.versionMinor < 4) { // NOTE : prior to Qt5.4 we had to link libGL manually
                                    ret.push ("GL");
                                }
                                return ret;
                            }
                    
                            cpp.cxxLanguageVersion: "c++14"
                            readonly property stringList qmlImportPaths : [sourceDirectory + "/import"]; // equivalent to QML_IMPORT_PATH += $$PWD/import
                    
                            Depends { name: "Qt.quick" }
                            Depends {
                                name: "Qt";
                                submodules: ["core", "gui", "qml", "quick","testlib","sql"];
                            }
                            Group{
                                name: "C++ sources";
                                files: [
                                    "planning.cpp",
                                    "main.cpp",
                                    "admin.cpp",
                                    "testPlanning.cpp",
                                    "user.cpp",
                                    "equipement.cpp",
                                    "equimenttablemodel.cpp",
                                    "palier.cpp",
                                    "paliermodel.cpp",
                                    "appwrapper.cpp",
                                ]
                            }
                            Group {
                                qbs.install: (product.type === "dynamiclibrary");
                                fileTagsFilter: product.type;
                            }
                    
                            Group{
                                name: "C++ headers";
                                files: [
                                    "admin.h",
                                    "appwrapper.h",
                                    "datetimevalidator.cpp",
                                    "datetimevalidator.h",
                                    "equimenttablemodel.h",
                                    "manager.cpp",
                                    "manager.h",
                                    "paliermodel.h",
                                    "planning.h",
                                    "user.h",
                                    "equipement.h",
                                    "palier.h",
                                ]
                            }
                            Group  {
                                name: "QML files"
                                files: [
                                    "DatePicker.qml",
                                    "DateUtils.js",
                                    "Planning.qml",
                                    "main.qml",
                                    "PagePlannification.qml",
                                    "qml.qrc",
                                ]
                            }
                    
                            //Depends { name: (project.namePrefixBase + "utils"); }
                            Depends { name: "libqtqmltricks-qtsupermacros"; }
                            Depends { name: "libqtqmltricks-qtqmlmodels"; }
                            Depends { name: "libqtqmltricks-qtquickuielements"; }
                        }
                    }
                    
                    
                    A Offline
                    A Offline
                    artwaw
                    wrote on 5 Mar 2020, 16:55 last edited by
                    #12

                    @Babs ups. I have literally zero experience with qbs...
                    I am afraid you'll have to wait for someone who knows something about it, I am sorry.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    1 Reply Last reply
                    0
                    • B Babs
                      5 Mar 2020, 16:47

                      @artwaw here is my QBS file

                      import qbs
                      
                      
                      
                      Project{
                          name: "PlanningModrian"
                      
                          Product{
                              files: [
                              ]
                              name: ( "modrian");
                              type: "application";
                              targetName: (project.targetPrefixTools + "modrian");
                              cpp.dynamicLibraries: {
                                  var ret = [];
                                  if (Qt.core.versionMinor < 4) { // NOTE : prior to Qt5.4 we had to link libGL manually
                                      ret.push ("GL");
                                  }
                                  return ret;
                              }
                      
                              cpp.cxxLanguageVersion: "c++14"
                              readonly property stringList qmlImportPaths : [sourceDirectory + "/import"]; // equivalent to QML_IMPORT_PATH += $$PWD/import
                      
                              Depends { name: "Qt.quick" }
                              Depends {
                                  name: "Qt";
                                  submodules: ["core", "gui", "qml", "quick","testlib","sql"];
                              }
                              Group{
                                  name: "C++ sources";
                                  files: [
                                      "planning.cpp",
                                      "main.cpp",
                                      "admin.cpp",
                                      "testPlanning.cpp",
                                      "user.cpp",
                                      "equipement.cpp",
                                      "equimenttablemodel.cpp",
                                      "palier.cpp",
                                      "paliermodel.cpp",
                                      "appwrapper.cpp",
                                  ]
                              }
                              Group {
                                  qbs.install: (product.type === "dynamiclibrary");
                                  fileTagsFilter: product.type;
                              }
                      
                              Group{
                                  name: "C++ headers";
                                  files: [
                                      "admin.h",
                                      "appwrapper.h",
                                      "datetimevalidator.cpp",
                                      "datetimevalidator.h",
                                      "equimenttablemodel.h",
                                      "manager.cpp",
                                      "manager.h",
                                      "paliermodel.h",
                                      "planning.h",
                                      "user.h",
                                      "equipement.h",
                                      "palier.h",
                                  ]
                              }
                              Group  {
                                  name: "QML files"
                                  files: [
                                      "DatePicker.qml",
                                      "DateUtils.js",
                                      "Planning.qml",
                                      "main.qml",
                                      "PagePlannification.qml",
                                      "qml.qrc",
                                  ]
                              }
                      
                              //Depends { name: (project.namePrefixBase + "utils"); }
                              Depends { name: "libqtqmltricks-qtsupermacros"; }
                              Depends { name: "libqtqmltricks-qtqmlmodels"; }
                              Depends { name: "libqtqmltricks-qtquickuielements"; }
                          }
                      }
                      
                      
                      B Offline
                      B Offline
                      Babs
                      wrote on 5 Mar 2020, 16:58 last edited by
                      #13

                      I resolved my problem. I made an error in the type an name of one of the parameters. Thanks for your help @artwaw.

                      A 1 Reply Last reply 5 Mar 2020, 17:01
                      1
                      • B Babs
                        5 Mar 2020, 16:58

                        I resolved my problem. I made an error in the type an name of one of the parameters. Thanks for your help @artwaw.

                        A Offline
                        A Offline
                        artwaw
                        wrote on 5 Mar 2020, 17:01 last edited by
                        #14

                        @Babs Anytime.
                        Please don't forget to mark the thread as "solved".

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        1 Reply Last reply
                        0

                        13/14

                        5 Mar 2020, 16:58

                        • Login

                        • Login or register to search.
                        13 out of 14
                        • First post
                          13/14
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved