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. Why shows error message when generating application release
Forum Updated to NodeBB v4.3 + New Features

Why shows error message when generating application release

Scheduled Pinned Locked Moved Solved General and Desktop
31 Posts 5 Posters 2.1k Views 1 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #3

    @SGaist said in Why shows error message when generating application release:

    When exactly do you have that error ?
    Are you starting your application from Windows's explorer ?

    The message is displayed when I click on the executable, in the Windows Explorer, which is created with the QTCREATOR.

    The application is not executed from the Windows Explorer, even when you add the corresponding libraries

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #4

      The error message is telling you that it does not have the proper libraries available in the enviornment the executable is running.

      Options:

      • There are (incorrect) Qt libraries on the system PATH found before those you intend.
      • Your libraries are from the wrong version of Qt (often this is because you have pulled the libs supporting Qt Creator rather than those you built against).
      • Your libraries are from the correct version of Qt but are the debug rather than release versions
      • There are no libraries to be found.

      The missing function should be in Qt5Core.dll library built with MingW.

      Please post the result of :

      • Windows command prompt TREE from the directory containing the EXE you are running
      • The value of PATH
      1 Reply Last reply
      2
      • lincolnL Offline
        lincolnL Offline
        lincoln
        wrote on last edited by lincoln
        #5

        Hello again friends, I was able to solve my problem, I was checking in the advanced configuration of the system and it happened that it had several values, in the PATH variable with paths to the Qt installation folder, so I deleted them all and with that I could solve my problem, thanks for your answers.

        now the problem is with respect to the database, I managed to generate the executable, add all the libraries you need, it happens that it does not show anything when I run it.

        e8231785-f45d-4939-9b10-6af4c62f6e20-image.png

        The application is already running, but the data is not displayed, which it queries from the DB.

        1 Reply Last reply
        1
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #6

          QSqlDatabase::open() returns true?

          1 Reply Last reply
          0
          • lincolnL Offline
            lincolnL Offline
            lincoln
            wrote on last edited by
            #7

            Yes, the connection returns true, when I test it in Qt Creator everything is fine, but when I test it on another pc, the data is not shown.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Did you properly deploy all dependencies ? Including the ones for the SQL driver you are using ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              lincolnL 1 Reply Last reply
              0
              • lincolnL Offline
                lincolnL Offline
                lincoln
                wrote on last edited by lincoln
                #9
                This post is deleted!
                1 Reply Last reply
                0
                • SGaistS SGaist

                  Did you properly deploy all dependencies ? Including the ones for the SQL driver you are using ?

                  lincolnL Offline
                  lincolnL Offline
                  lincoln
                  wrote on last edited by lincoln
                  #10

                  @SGaist
                  Of course, as you can see in the previous image that I publish, there are all the dependencies, those of the database and others that the application needs, which automatically adds windeployqt, and those that I add, manually such as:

                  libpq.dll
                  libcrypto-1_1-x64.dll
                  libiconv-2.dll
                  libintl-8.dll
                  libssl-1_1-x64.dll.

                  I am using PostgreSQL version 13.3 and Qt 5.15.2. Both 64-bit

                  These libraries correspond to PostgreSQL, as I did my tests in Qt Creator, they work fine there, but when I create the exe and run from there, nothing happens.

                  Even so, the data is not shown; And it doesn't occur to me what else it could be.

                  Here run from the Qt Creator, the data is shown without problems, which does not happen when I deploy the application.
                  74843d4c-81f7-4d16-b7f8-5932e0ca7829-image.png

                  jsulmJ SGaistS 2 Replies Last reply
                  0
                  • lincolnL lincoln

                    @SGaist
                    Of course, as you can see in the previous image that I publish, there are all the dependencies, those of the database and others that the application needs, which automatically adds windeployqt, and those that I add, manually such as:

                    libpq.dll
                    libcrypto-1_1-x64.dll
                    libiconv-2.dll
                    libintl-8.dll
                    libssl-1_1-x64.dll.

                    I am using PostgreSQL version 13.3 and Qt 5.15.2. Both 64-bit

                    These libraries correspond to PostgreSQL, as I did my tests in Qt Creator, they work fine there, but when I create the exe and run from there, nothing happens.

                    Even so, the data is not shown; And it doesn't occur to me what else it could be.

                    Here run from the Qt Creator, the data is shown without problems, which does not happen when I deploy the application.
                    74843d4c-81f7-4d16-b7f8-5932e0ca7829-image.png

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    @lincoln said in Why shows error message when generating application release:

                    And it doesn't occur to me what else it could be

                    Set QT_DEBUG_PLUGINS to 1 before starting you app from terminal and put the output here.
                    https://doc.qt.io/qt-5/debug.html

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

                    lincolnL 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @lincoln said in Why shows error message when generating application release:

                      And it doesn't occur to me what else it could be

                      Set QT_DEBUG_PLUGINS to 1 before starting you app from terminal and put the output here.
                      https://doc.qt.io/qt-5/debug.html

                      lincolnL Offline
                      lincolnL Offline
                      lincoln
                      wrote on last edited by
                      #12

                      @jsulm Thanks for your answer, but I don't really know how to do what you tell me, thank you anyway.

                      JonBJ 1 Reply Last reply
                      0
                      • lincolnL lincoln

                        @jsulm Thanks for your answer, but I don't really know how to do what you tell me, thank you anyway.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #13

                        @lincoln
                        Use the forum Search for QT_DEBUG_PLUGINS. We don't want to answer the same question from many users over and over. It's also in the docs at Environment Variables Recognized by Qt. You need to read and act on these.

                        lincolnL 1 Reply Last reply
                        1
                        • lincolnL lincoln

                          @SGaist
                          Of course, as you can see in the previous image that I publish, there are all the dependencies, those of the database and others that the application needs, which automatically adds windeployqt, and those that I add, manually such as:

                          libpq.dll
                          libcrypto-1_1-x64.dll
                          libiconv-2.dll
                          libintl-8.dll
                          libssl-1_1-x64.dll.

                          I am using PostgreSQL version 13.3 and Qt 5.15.2. Both 64-bit

                          These libraries correspond to PostgreSQL, as I did my tests in Qt Creator, they work fine there, but when I create the exe and run from there, nothing happens.

                          Even so, the data is not shown; And it doesn't occur to me what else it could be.

                          Here run from the Qt Creator, the data is shown without problems, which does not happen when I deploy the application.
                          74843d4c-81f7-4d16-b7f8-5932e0ca7829-image.png

                          SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          @lincoln said in Why shows error message when generating application release:

                          Here run from the Qt Creator, the data is shown without problems, which does not happen when I deploy the application.

                          Do you run that deployed version on your machine or on a different machine ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          lincolnL 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            @lincoln said in Why shows error message when generating application release:

                            Here run from the Qt Creator, the data is shown without problems, which does not happen when I deploy the application.

                            Do you run that deployed version on your machine or on a different machine ?

                            lincolnL Offline
                            lincolnL Offline
                            lincoln
                            wrote on last edited by
                            #15

                            @SGaist First I tried it on my machine, and then I took it to a different one, where the Qt was not installed, and the same result.

                            1 Reply Last reply
                            0
                            • JonBJ JonB

                              @lincoln
                              Use the forum Search for QT_DEBUG_PLUGINS. We don't want to answer the same question from many users over and over. It's also in the docs at Environment Variables Recognized by Qt. You need to read and act on these.

                              lincolnL Offline
                              lincolnL Offline
                              lincoln
                              wrote on last edited by
                              #16

                              @JonB ok, thanks

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #17

                                Then the next step is to start your application from the command line with QT_DEBUG_PLUGINS set to 1 to see what is going on.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                lincolnL 2 Replies Last reply
                                0
                                • SGaistS SGaist

                                  Then the next step is to start your application from the command line with QT_DEBUG_PLUGINS set to 1 to see what is going on.

                                  lincolnL Offline
                                  lincolnL Offline
                                  lincoln
                                  wrote on last edited by
                                  #18
                                  This post is deleted!
                                  1 Reply Last reply
                                  0
                                  • SGaistS SGaist

                                    Then the next step is to start your application from the command line with QT_DEBUG_PLUGINS set to 1 to see what is going on.

                                    lincolnL Offline
                                    lincolnL Offline
                                    lincoln
                                    wrote on last edited by
                                    #19

                                    @SGaist ok thanks, i'll find out how to do that.

                                    1 Reply Last reply
                                    0
                                    • lincolnL Offline
                                      lincolnL Offline
                                      lincoln
                                      wrote on last edited by
                                      #20

                                      THIS IS A MESSAGE THAT IS DISPLAYED AFTER STARTING THE APP WITH QT_DEBUG_PLUGINS

                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers" ...
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlite.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlite.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "QSQLITE"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QSQLiteDriverPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("QSQLITE")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlodbc.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlodbc.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "QODBC"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QODBCDriverPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("QODBC")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlpsql.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlpsql.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "QPSQL"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QPSQLDriverPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("QPSQL")
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/sqldrivers/qsqlpsql.dll"
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/platforms" ...
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/platforms/qdirect2d.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/platforms/qdirect2d.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
                                      "MetaData": {
                                      "Keys": [
                                      "direct2d"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QWindowsDirect2DIntegrationPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("direct2d")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/platforms/qminimal.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/platforms/qminimal.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
                                      "MetaData": {
                                      "Keys": [
                                      "minimal"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QMinimalIntegrationPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("minimal")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/platforms/qoffscreen.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/platforms/qoffscreen.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
                                      "MetaData": {
                                      "Keys": [
                                      "offscreen"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QOffscreenIntegrationPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("offscreen")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/platforms/qwindows.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/platforms/qwindows.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
                                      "MetaData": {
                                      "Keys": [
                                      "windows"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QWindowsIntegrationPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("windows")
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/platforms" ...
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/platforms/qwindows.dll"
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/platformthemes" ...
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/platformthemes" ...
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/styles" ...
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/styles/qwindowsvistastyle.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/styles/qwindowsvistastyle.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QStyleFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "windowsvista"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QWindowsVistaStylePlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("windowsvista")
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/styles" ...
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/styles/qwindowsvistastyle.dll"
                                      QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
                                      QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/iconengines" ...
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/iconengines/qsvgicon.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/iconengines/qsvgicon.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QIconEngineFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "svg",
                                      "svgz",
                                      "svg.gz"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QSvgIconPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("svg", "svgz", "svg.gz")
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/iconengines" ...
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/imageformats" ...
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qgif.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qgif.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "gif"
                                      ],
                                      "MimeTypes": [
                                      "image/gif"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QGifPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("gif")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qico.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qico.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "ico",
                                      "cur"
                                      ],
                                      "MimeTypes": [
                                      "image/vnd.microsoft.icon",
                                      "image/vnd.microsoft.icon"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QICOPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("ico", "cur")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qjpeg.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qjpeg.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "jpg",
                                      "jpeg"
                                      ],
                                      "MimeTypes": [
                                      "image/jpeg",
                                      "image/jpeg"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QJpegPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("jpg", "jpeg")
                                      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qsvg.dll"
                                      Found metadata in lib C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qsvg.dll, metadata=
                                      {
                                      "IID": "org.qt-project.Qt.QImageIOHandlerFactoryInterface",
                                      "MetaData": {
                                      "Keys": [
                                      "svg",
                                      "svgz"
                                      ],
                                      "MimeTypes": [
                                      "image/svg+xml",
                                      "image/svg+xml-compressed"
                                      ]
                                      },
                                      "archreq": 0,
                                      "className": "QSvgPlugin",
                                      "debug": false,
                                      "version": 393472
                                      }

                                      Got keys from plugin meta data QList("svg", "svgz")
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/imageformats" ...
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qgif.dll"
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qico.dll"
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qjpeg.dll"
                                      loaded library "C:/Qt/6.1.2/mingw81_64/plugins/imageformats/qsvg.dll"
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/accessible" ...
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/accessible" ...
                                      QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
                                      La carpeta ya existe
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/6.1.2/mingw81_64/plugins/accessiblebridge" ...
                                      QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/USER/Downloads/build-monitoreo_xertek-Desktop_Qt_6_1_2_MinGW_64_bit-Release/release/accessiblebridge" ...

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #21

                                        @lincoln said in Why shows error message when generating application release:

                                        QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

                                        You are still creating multiple QSqlDatabase objects using the default connection. One might be wrong.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        lincolnL 1 Reply Last reply
                                        1
                                        • SGaistS SGaist

                                          @lincoln said in Why shows error message when generating application release:

                                          QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

                                          You are still creating multiple QSqlDatabase objects using the default connection. One might be wrong.

                                          lincolnL Offline
                                          lincolnL Offline
                                          lincoln
                                          wrote on last edited by lincoln
                                          #22

                                          @SGaist I changed the code in this way, but now it does not connect to the database, I think it is worse.

                                          DbConection class

                                          #ifndef DBCONECTION_H
                                          #define DBCONECTION_H
                                          #include <QSqlDatabase>
                                          #include <QSqlError>
                                          
                                          class DbConection
                                          {
                                          public:
                                            DbConection();
                                            bool connect(const QString &dbName);
                                            QString errorMessage(){return _errorMessage;}
                                            QSqlDatabase getDataBase();
                                          //  void removeDb();
                                          
                                          
                                          private:
                                            QString _errorMessage;
                                            QString mdbName;
                                          
                                          };
                                          
                                          #endif // DBCONECTION_H
                                          
                                          #include "dbconection.h"
                                          
                                          
                                          DbConection::DbConection(){
                                          
                                          }
                                          
                                          bool DbConection::connect(const QString &dbName)
                                          {
                                            mdbName=dbName;
                                            auto db=QSqlDatabase::addDatabase("QPSQL",dbName);
                                            if(!db.isDriverAvailable("QPSQL")){
                                                _errorMessage=db.lastError().driverText();
                                                return false;
                                              }
                                            db.setDatabaseName("monitoreo_db");
                                            db.setPort(5432);
                                            db.setHostName("127.0.0.1");
                                            db.setUserName("postgres");
                                            db.setPassword("2311046");
                                          
                                            if(!db.open()){
                                                _errorMessage=db.lastError().databaseText();
                                                return false;
                                              }
                                          
                                            return true;
                                          
                                          }
                                          
                                          QSqlDatabase DbConection::getDataBase()
                                          {
                                          
                                            return QSqlDatabase::database(mdbName);
                                          
                                          }
                                          

                                          BussinesLayer class:

                                          #ifndef BUSSINESLAYER_H
                                          #define BUSSINESLAYER_H
                                          
                                          #include <QSqlQuery>
                                          #include <QSqlError>
                                          #include "dbconection.h"
                                          
                                          class BussinesLayer : public QObject
                                          {
                                          
                                          public:
                                            BussinesLayer();  
                                            QVariantList selectData(QVariant id);
                                            
                                          private:
                                            QString _errorMessage;
                                            QString _errorCode;  
                                            DbConection db;
                                            
                                          };
                                          
                                          #endif // BUSSINESLAYER_H
                                          
                                          
                                          #include "bussineslayer.h"
                                          
                                          BussinesLayer::BussinesLayer()
                                          {
                                          
                                            db.connect("monitoreo");
                                          
                                          }
                                          
                                          QVariantList BussinesLayer::selectData(QVariant id)
                                          {
                                            QVariantList dataList;
                                            QSqlQuery qry(db.getDataBase());
                                            qry.prepare("SELECT * FROM grupo_minero WHERE id=?");
                                            qry.addBindValue(id);
                                            if(!qry.exec()){
                                              _errorMessage=qry.lastError().text();
                                              return dataList;
                                          }        
                                            return dataList;
                                          
                                          }
                                          

                                          now this message comes out
                                          90eb8376-77a3-4919-b820-17dab02b9cab-image.png
                                          😟😠

                                          jsulmJ 1 Reply Last reply
                                          0

                                          • Login

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