Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9201551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:02:24+00:00 2026-06-17T23:02:24+00:00

In a library I am developing I have a class that I want to

  • 0

In a library I am developing I have a class that I want to have a hash storing any kind of data. This is because an algorithm using this library may want to store specific data in the objects of that class.

The class is called “ObjectOfInterest” where I have defined the hash using QT:

QHash<QString, void*> properties;

Then I have implemented this functions to store information:

bool ObjectOfInterest::hasProperty(QString prop) const
{
    return properties.contains(prop);
}

template <class T> const T& ObjectOfInterest::getProperty(const QString prop) const
{
    return *(T *)properties.value(prop);
}

template <class T> void ObjectOfInterest::setProperty(const QString prop, T value)
{
    if (hasProperty(prop)) deletePropertyValue<T>(prop);
    properties.insert(prop, new T(value));
}

//private
template <class T> void ObjectOfInterest::deletePropertyValue(const QString prop)
{
    delete (T *)properties.value(prop);
}

Now the question is, when deleting an object of “ObjectOfInterest”, how can I delete all values stored in the properties hash? For now I have

ObjectOfInterest::~ObjectOfInterest()
{
    //delete other stuff...

    QHash<QString, void*>::iterator i;
    for (i = properties.begin(); i != properties.end(); ++i)
    {
        delete i.value();
    }
}

But this is not a solution, as I am not calling the destructor. Any ideas how to do this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:02:26+00:00Added an answer on June 17, 2026 at 11:02 pm

    Finally the solution was using boost::any

    //ObjectOfInterest.h
    public:
        ...
        bool    hasProperty(const string & prop) const;
        void    emplaceProperty(const string & prop, boost::any value);
        void    setProperty(const string & prop, boost::any value);
        template <class T> const T property(const string & prop) const
        {
        return any_cast<T>(properties.at(prop));
        }
    ...
    private:
        ...
        boost::unordered::unordered_map<string, boost::any> properties;
    

    //ObjectOfInterest.cpp
    ...
    bool ObjectOfInterest::hasProperty(const string & prop) const
    {
        return properties.find(prop)!=properties.end();
    }
    
    void ObjectOfInterest::emplaceProperty(const string & prop, any value)
    {
        properties.emplace(prop, value);
    }
    
    void ObjectOfInterest::setProperty(const string & prop, any value)
    {
        properties[prop] = value;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a class library that implements a protocol stack. There I have an
I am developing a class library that will be used in several projects. In
i am developing a GUI , using java Swing library .I want to add
I am developing a portable class library in C# and I want to bit
Our team is currently developing a web application, in that we have a class
I'm developing a class library that will be used in a number of different
I am developing a library that will be used to marshall and unmarshall data
I'm building a class library that will have some public & private methods. I
I am developing a portable class library that needs to make REST requests and
I'm developing a shared library. Let's say I have the following class definition: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.