Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Starting with Qt Creator - Sql problem
Forum Update on Monday, May 27th 2025

Starting with Qt Creator - Sql problem

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
10 Posts 3 Posters 963 Views
  • 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.
  • S Offline
    S Offline
    Seabird
    wrote on 25 Apr 2022, 12:01 last edited by Seabird
    #1

    Hi everyone,
    as a brand new user of QT creator I stumble into some problems trying to follow a simple tutorial to aid my learning curve. I want to create a simple database.

    I created a new project and selected Application -> Widgets Application
    in my .pro file I added QT += sql
    in my main.cpp I added #include <QtSql/QSqlDatabase>

    Now I try to create a database using

    QSqlDatabase db;
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("/home/myspace/testdb.sqlite");
    

    Now I was expecting it to recognize QSqlDatabase, but it only recognizes QT_SQL_LIB

    Did I go wrong installing, configuring or is the tutorial I am trying to follow outdated?

    I did try running clean and qmake after adding sql to my .pro file.

    C 1 Reply Last reply 25 Apr 2022, 12:03
    0
    • S Seabird
      25 Apr 2022, 12:53

      @jsulm I see these in QT Creator when I go to the issues tab (and in the file editor labeled red at the end of the line).

      When I run the project the database is not creating also indicating things are not going to plan.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 25 Apr 2022, 12:56 last edited by
      #8

      @Seabird So, your project builds, right? The error in editor are a known problem with code model.
      "When I run the project the database is not creating" - because you do not open the database.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 25 Apr 2022, 13:04
      1
      • S Seabird
        25 Apr 2022, 12:01

        Hi everyone,
        as a brand new user of QT creator I stumble into some problems trying to follow a simple tutorial to aid my learning curve. I want to create a simple database.

        I created a new project and selected Application -> Widgets Application
        in my .pro file I added QT += sql
        in my main.cpp I added #include <QtSql/QSqlDatabase>

        Now I try to create a database using

        QSqlDatabase db;
        db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("/home/myspace/testdb.sqlite");
        

        Now I was expecting it to recognize QSqlDatabase, but it only recognizes QT_SQL_LIB

        Did I go wrong installing, configuring or is the tutorial I am trying to follow outdated?

        I did try running clean and qmake after adding sql to my .pro file.

        C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 25 Apr 2022, 12:03 last edited by
        #2

        @Seabird said in Starting with Qt Creator - Sql problem:

        Now I was expecting it to recognize QSqlDatabase, but it only recognizes QT_SQL_LIB

        What does this mean? Do you get a compiler error?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        S 1 Reply Last reply 25 Apr 2022, 12:12
        0
        • C Christian Ehrlicher
          25 Apr 2022, 12:03

          @Seabird said in Starting with Qt Creator - Sql problem:

          Now I was expecting it to recognize QSqlDatabase, but it only recognizes QT_SQL_LIB

          What does this mean? Do you get a compiler error?

          S Offline
          S Offline
          Seabird
          wrote on 25 Apr 2022, 12:12 last edited by
          #3

          @Christian-Ehrlicher it gives me unknow type name 'QSqlDatabase'
          and in the compiler it kicks a error undifened reference to QSqlDatabase::QSqlDatabase()

          (sorry for slow responds, but am only allowed to reply every 10 minutes)

          J 1 Reply Last reply 25 Apr 2022, 12:22
          0
          • S Seabird
            25 Apr 2022, 12:12

            @Christian-Ehrlicher it gives me unknow type name 'QSqlDatabase'
            and in the compiler it kicks a error undifened reference to QSqlDatabase::QSqlDatabase()

            (sorry for slow responds, but am only allowed to reply every 10 minutes)

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 25 Apr 2022, 12:22 last edited by
            #4

            @Seabird The include should look like this:

            #include <QSqlDatabase>
            

            And after changing pro file you should do complete rebuild:

            • Delete build folder
            • Run qmake
            • build

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Seabird
              wrote on 25 Apr 2022, 12:43 last edited by
              #5

              Ok, the video tutorial I am trying to follow is slightly outdated (2017) but the goal is the same:

              This is the tutorial I am trying to follow: youtube tutorial

              My sqltest.pro

              QT -= gui
              QT += core sql
              
              CONFIG += c++11 console
              CONFIG -= app_bundle
              
              DEFINES += QT_DEPRECATED_WARNINGS
              
              deprecated before Qt 6.0.0
              
              SOURCES += \
                      main.cpp
              
              # Default rules for deployment.
              qnx: target.path = /tmp/$${TARGET}/bin
              else: unix:!android: target.path = /opt/$${TARGET}/bin
              !isEmpty(target.path): INSTALLS += target
              
              

              and my main.cpp

              #include <QCoreApplication>
              #include <QSqlDatabase>
              
              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
              
                  QSqlDatabase db;
                  db = QSqlDatabase::addDatabase("QSQLITE");
                  db.setDatabaseName("/home/jacco/testdb.sqlite");
              
                  return a.exec();
              }
              
              

              I cleaned build folder, ran qmake, build etc.

              Three issues reported:

              • list item unknown type name 'QCoreApplication'
              • list item unknown type name 'QSqlDatabase'
              • list item use of undeclared identifier 'QSqlDatabase'
              J 1 Reply Last reply 25 Apr 2022, 12:46
              0
              • S Seabird
                25 Apr 2022, 12:43

                Ok, the video tutorial I am trying to follow is slightly outdated (2017) but the goal is the same:

                This is the tutorial I am trying to follow: youtube tutorial

                My sqltest.pro

                QT -= gui
                QT += core sql
                
                CONFIG += c++11 console
                CONFIG -= app_bundle
                
                DEFINES += QT_DEPRECATED_WARNINGS
                
                deprecated before Qt 6.0.0
                
                SOURCES += \
                        main.cpp
                
                # Default rules for deployment.
                qnx: target.path = /tmp/$${TARGET}/bin
                else: unix:!android: target.path = /opt/$${TARGET}/bin
                !isEmpty(target.path): INSTALLS += target
                
                

                and my main.cpp

                #include <QCoreApplication>
                #include <QSqlDatabase>
                
                int main(int argc, char *argv[])
                {
                    QCoreApplication a(argc, argv);
                
                    QSqlDatabase db;
                    db = QSqlDatabase::addDatabase("QSQLITE");
                    db.setDatabaseName("/home/jacco/testdb.sqlite");
                
                    return a.exec();
                }
                
                

                I cleaned build folder, ran qmake, build etc.

                Three issues reported:

                • list item unknown type name 'QCoreApplication'
                • list item unknown type name 'QSqlDatabase'
                • list item use of undeclared identifier 'QSqlDatabase'
                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 25 Apr 2022, 12:46 last edited by
                #6

                @Seabird said in Starting with Qt Creator - Sql problem:

                Three issues reported

                To make things clear: do you get this errors in QtCreator inside editor, or do you get them when you compile your project?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply 25 Apr 2022, 12:53
                0
                • J jsulm
                  25 Apr 2022, 12:46

                  @Seabird said in Starting with Qt Creator - Sql problem:

                  Three issues reported

                  To make things clear: do you get this errors in QtCreator inside editor, or do you get them when you compile your project?

                  S Offline
                  S Offline
                  Seabird
                  wrote on 25 Apr 2022, 12:53 last edited by
                  #7

                  @jsulm I see these in QT Creator when I go to the issues tab (and in the file editor labeled red at the end of the line).

                  When I run the project the database is not creating also indicating things are not going to plan.

                  J 1 Reply Last reply 25 Apr 2022, 12:56
                  0
                  • S Seabird
                    25 Apr 2022, 12:53

                    @jsulm I see these in QT Creator when I go to the issues tab (and in the file editor labeled red at the end of the line).

                    When I run the project the database is not creating also indicating things are not going to plan.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 25 Apr 2022, 12:56 last edited by
                    #8

                    @Seabird So, your project builds, right? The error in editor are a known problem with code model.
                    "When I run the project the database is not creating" - because you do not open the database.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    S 1 Reply Last reply 25 Apr 2022, 13:04
                    1
                    • J jsulm
                      25 Apr 2022, 12:56

                      @Seabird So, your project builds, right? The error in editor are a known problem with code model.
                      "When I run the project the database is not creating" - because you do not open the database.

                      S Offline
                      S Offline
                      Seabird
                      wrote on 25 Apr 2022, 13:04 last edited by
                      #9

                      @jsulm I missed the last db.open statement. Thank you

                      Like I said, I am completely new to this. Steep learning curve

                      Any reason it does not recognize the QSqlDatabase statements? Makes my typing a lot less insecure now

                      J 1 Reply Last reply 25 Apr 2022, 13:07
                      0
                      • S Seabird
                        25 Apr 2022, 13:04

                        @jsulm I missed the last db.open statement. Thank you

                        Like I said, I am completely new to this. Steep learning curve

                        Any reason it does not recognize the QSqlDatabase statements? Makes my typing a lot less insecure now

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 25 Apr 2022, 13:07 last edited by
                        #10

                        @Seabird said in Starting with Qt Creator - Sql problem:

                        Any reason it does not recognize the QSqlDatabase statements?

                        Yes, known issue with clang code model. You can disable it, go to: "Help/About Plugins..." and disable ClangCodeModel plug-in.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        1/10

                        25 Apr 2022, 12:01

                        • Login

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