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

Question about store data

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 99 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 22 days ago 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?
    }

    P 1 Reply Last reply 22 days ago
    0
    • D DmitryTS
      22 days ago

      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?
      }

      P Offline
      P Offline
      Pl45m4
      wrote 22 days ago 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 21 days ago
      0
      • P Pl45m4
        22 days ago

        @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 21 days ago 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

        1/3

        21 Apr 2025, 13:44

        • Login

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