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. Question about store data
QtWS25 Last Chance

Question about store data

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 96 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.
  • D Offline
    D Offline
    DmitryTS
    wrote last edited by
    #1

    Hello, I have a question, I am implementing a single tone class for connecting to databases, the main task is to place the database in a pool when connecting, I use the PIMPL approach to store data, but here is the question, if a smart pointer is used, then it cannot be copied and placed in a pool, and in principle the logic is broken, it seems to me, what is the best way to implement this?

    DbConnection.h

    Class DbConnection{
    private:
    DbConnection() = default;
    struct Data;
    std::unique_ptr<Data> pData;
    //other code
    public:
    QList<std::unique_ptr<Data>> poolConnections;
    bool connect();
    //
    }

    DbConnection.cpp

    struct DbConnection::Data{
    QString host;
    QString port;
    //other
    }

    bool connect(){

    ….
    how to add each new connection to pool?
    }

    Pl45m4P 1 Reply Last reply
    0
    • D DmitryTS

      Hello, I have a question, I am implementing a single tone class for connecting to databases, the main task is to place the database in a pool when connecting, I use the PIMPL approach to store data, but here is the question, if a smart pointer is used, then it cannot be copied and placed in a pool, and in principle the logic is broken, it seems to me, what is the best way to implement this?

      DbConnection.h

      Class DbConnection{
      private:
      DbConnection() = default;
      struct Data;
      std::unique_ptr<Data> pData;
      //other code
      public:
      QList<std::unique_ptr<Data>> poolConnections;
      bool connect();
      //
      }

      DbConnection.cpp

      struct DbConnection::Data{
      QString host;
      QString port;
      //other
      }

      bool connect(){

      ….
      how to add each new connection to pool?
      }

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by
      #2

      @DmitryTS

      Hi, your design seems a bit unusual but the easiest way is to store one instance/smart pointer of something like ConnectionData in your singleton (instead of a list). And in ConnectionData you store a list of your actual connection data.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      D 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @DmitryTS

        Hi, your design seems a bit unusual but the easiest way is to store one instance/smart pointer of something like ConnectionData in your singleton (instead of a list). And in ConnectionData you store a list of your actual connection data.

        D Offline
        D Offline
        DmitryTS
        wrote last edited by
        #3

        @Pl45m4 honestly, I haven't decided how best to implement it, I thought maybe there was another alternative? I didn't fully understand what you meant, just store in the auxiliary structure not the data but the list of connections?

        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