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
    #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" ...

    Solitary wolf

    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
        😟😠

        Solitary wolf

        jsulmJ 1 Reply Last reply
        0
        • lincolnL lincoln

          @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 Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #23

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

          DbConection::connect(const QString &dbName)

          ^Where do you call it now in your code? You need to call it once before using the database connection.

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

          JonBJ 1 Reply Last reply
          0
          • jsulmJ jsulm

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

            DbConection::connect(const QString &dbName)

            ^Where do you call it now in your code? You need to call it once before using the database connection.

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

            @jsulm
            He calls it in the BussinesLayer::BussinesLayer() constructor: db.connect("monitoreo");.

            @lincoln
            In DbConection::connect() you check for db.isDriverAvailable("QPSQL") after you have called QSqlDatabase::addDatabase(). I suggest you want to call it before.

            On error you set _errorMessage and return false, yet you don't check for that nor show the error message.

            Your console output still shows "duplicate connection", which implies you are still calling DbConection::connect() more than once. Since you call it from BussinesLayer constructor, maybe your outside world code creates a BussinesLayer more than once.

            Can you please put in your own qDebug() messages to see what is getting executed in your own code, and for your error messages. This is a standard part of programming. For example, put one in at the start of DbConection::connect(). If that gets printed out more than once, you are in trouble....

            lincolnL 1 Reply Last reply
            2
            • JonBJ JonB

              @jsulm
              He calls it in the BussinesLayer::BussinesLayer() constructor: db.connect("monitoreo");.

              @lincoln
              In DbConection::connect() you check for db.isDriverAvailable("QPSQL") after you have called QSqlDatabase::addDatabase(). I suggest you want to call it before.

              On error you set _errorMessage and return false, yet you don't check for that nor show the error message.

              Your console output still shows "duplicate connection", which implies you are still calling DbConection::connect() more than once. Since you call it from BussinesLayer constructor, maybe your outside world code creates a BussinesLayer more than once.

              Can you please put in your own qDebug() messages to see what is getting executed in your own code, and for your error messages. This is a standard part of programming. For example, put one in at the start of DbConection::connect(). If that gets printed out more than once, you are in trouble....

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

              @JonB a business layer, I call it from several forms, in the private part of the .h file of each form, I declare a variable of type bussineslayer class, in that class I have all the code I need to be able to do the DB tasks.

              here for example in "mainwindow.h"

              a8cf38a1-159e-434c-8b08-280082413839-image.png

              and so on all the forms you need from the bussineslayer class.

              Use a QMessageBox, to display the message and this is what it displays
              d9357a81-1d27-4e34-9206-e580ae62cbee-image.png

              I don't understand, when I don't pass the name of the connection in QSqlDatabase :: addDatabase ("QPSQL", dbName);
              data is displayed normally.

              Solitary wolf

              JonBJ 1 Reply Last reply
              0
              • lincolnL lincoln

                @JonB a business layer, I call it from several forms, in the private part of the .h file of each form, I declare a variable of type bussineslayer class, in that class I have all the code I need to be able to do the DB tasks.

                here for example in "mainwindow.h"

                a8cf38a1-159e-434c-8b08-280082413839-image.png

                and so on all the forms you need from the bussineslayer class.

                Use a QMessageBox, to display the message and this is what it displays
                d9357a81-1d27-4e34-9206-e580ae62cbee-image.png

                I don't understand, when I don't pass the name of the connection in QSqlDatabase :: addDatabase ("QPSQL", dbName);
                data is displayed normally.

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

                @lincoln
                Please copy & paste code rather than a screenshot. Same for error messages. It makes life easier for everyone.

                You have written code to create a new database connection, unconditionally, in BussinesLayer's constructor. If you have multiple BussinesLayer instances you will be creating multiple, duplicate connections. As per the error message you showed you get.

                You don't want that, do you? Multiple connections to the database? So you had better change code not to do that. Why do you have multiple BussinesLayer' instances anyway?

                lincolnL 1 Reply Last reply
                0
                • JonBJ JonB

                  @lincoln
                  Please copy & paste code rather than a screenshot. Same for error messages. It makes life easier for everyone.

                  You have written code to create a new database connection, unconditionally, in BussinesLayer's constructor. If you have multiple BussinesLayer instances you will be creating multiple, duplicate connections. As per the error message you showed you get.

                  You don't want that, do you? Multiple connections to the database? So you had better change code not to do that. Why do you have multiple BussinesLayer' instances anyway?

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

                  @JonB

                  Ok, I saw what my error is, I was not passing the name of the connection when creating my QsqlQuery.
                  now if it shows the data without problems. so I remain.

                  class for connection to DB:

                  #ifndef DBCONECTION_H
                  #define DBCONECTION_H
                  #include <QSqlDatabase>
                  #include <QSqlError>
                  #include <QObject>
                  
                  
                  class DbConection: public QObject
                  {
                  public:
                    explicit DbConection(QObject *parent=nullptr);
                    bool connect(const QString &dbName);
                    QString errorMessage(){return _errorMessage;}
                    QSqlDatabase getDataBase();
                  //  void removeDb();
                  
                  private:
                    QString _errorMessage;
                    QString mdbName;
                  
                  };
                  
                  #endif // DBCONECTION_H
                  
                  
                  #include "dbconection.h"
                  #include <QDebug>
                  
                  DbConection::DbConection(QObject *parent):
                    QObject(parent)
                  {
                  
                  }
                  
                  bool DbConection::connect(const QString &dbName)
                  {
                    mdbName=dbName;
                    //  auto db=QSqlDatabase::addDatabase("QPSQL",dbName);
                    QSqlDatabase db;
                    if(!db.isDriverAvailable("QPSQL")){
                        _errorMessage=db.lastError().driverText();
                  //      qDebug()<<_errorMessage;
                        return false;
                      }
                    db=QSqlDatabase::addDatabase("QPSQL",dbName);
                    db.setPort(5432);
                    db.setHostName("127.0.0.1");
                    db.setDatabaseName("monitoreo_db");
                    db.setUserName("postgres");
                    db.setPassword("2311046");
                  
                    if(!db.open()){
                        _errorMessage=db.lastError().databaseText();
                  //      qDebug()<<_errorMessage;
                        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:
                    explicit BussinesLayer(QObject *parent=nullptr);
                    QHash<int, QString> selectDataClient();
                    
                  private:
                    QString _errorMessage;
                    QString _errorCode;  
                    DbConection db;
                    
                  };
                  
                  #endif // BUSSINESLAYER_H
                  
                  
                  #include "bussineslayer.h"
                  #include <QDebug>
                  BussinesLayer::BussinesLayer(QObject *parent):
                    QObject(parent)
                  {
                  
                    if(!db.connect("monitoreo"))
                      qDebug()<<db.errorMessage();
                  
                  }
                  
                  QHash<int, QString> BussinesLayer::selectDataClient()
                  {
                    QHash<int,QString> dataList;
                  
                    QSqlQuery qry(db.getDataBase());
                    qry.prepare("SELECT id,nombre_unidad FROM cliente");
                  
                    if(!qry.exec()){
                        _errorMessage=qry.lastError().text();
                         return dataList;
                      }
                    while(qry.next()){
                        dataList.insert(qry.value(0).toInt(),qry.value(1).toString());
                      }
                    return dataList;
                  }
                  

                  And this in the mainwindow:

                  private:
                    Ui::MainWindow *ui;
                    BussinesLayer bLayer;
                  
                  void MainWindow::loadData()
                  {
                    QHash<int,QString> dataList;
                    dataList=bLayer.selectDataClient();
                    if(dataList.isEmpty()){
                        QMessageBox::critical(this,qApp->applicationName(),bLayer.errorMessage());
                        return;
                      }
                    ui->cboGrupo->addItems(dataList.values());  
                  
                  }
                  

                  But still the duplicate connection message persists, as I mentioned above, I have to create a new variable of type BussinesLayer in the other forms, in order to have access to the other data that I use in the other forms.

                  Solitary wolf

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

                    Because if you have several BusinessLayer objects, they will all use the same named connection the way you implemented it.

                    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

                      Because if you have several BusinessLayer objects, they will all use the same named connection the way you implemented it.

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

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

                      Because if you have several BusinessLayer objects, they will all use the same named connection the way you implemented it.

                      Well, I was also able to solve the issue of generating the release, now the data is displayed correctly, what remains in doubt is, how do I access the functionality of my BussinesLayer class in the other forms, without that annoying message of duplicate connection.

                      šŸ˜’ 🄓

                      Solitary wolf

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

                        Currently you are using the same connection everywhere thus as we already suggested several times: do the initialisation once and be done with it.

                        The other solution is to create a different named connection for each instance of BusinessLayer.

                        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

                          Currently you are using the same connection everywhere thus as we already suggested several times: do the initialisation once and be done with it.

                          The other solution is to create a different named connection for each instance of BusinessLayer.

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

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

                          Currently you are using the same connection everywhere thus as we already suggested several times: do the initialisation once and be done with it.
                          The other solution is to create a different named connection for each instance of BusinessLayer.

                          ok thanks

                          Solitary wolf

                          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