11-21-2012 06:38 PM
Hi all,
I downloaded some sample code:
https://github.com/blackberry/Presentations/tree/m
You will notice in the app.cpp and app.h files, the following lines in bold.
app.cpp
SoundPartyApp::SoundPartyApp()
{
// create the qml etc.
mSoundManager = new SoundManager("sounds/");
}
SoundPartyApp::~SoundPartyApp()
{
// Destroy the sound manager.
delete mSoundManager;
}
app.h
class SoundPartyApp: public QObject
{
Q_OBJECT
public:
// This is our constructor to setup our badumtss2 application
SoundPartyApp();
// This is our destructor that frees the memory of the sound manager
~SoundPartyApp();
// more stuff here etc
private:
// The sound manager
SoundManager *mSoundManager;
};
I understand this is with the old c++ code. The new app.hpp which I am using in beta 3, therefore, has a different "virtual" destructor:
class SoundPartyApp : public QObject
{
Q_OBJECT
public:
SoundPartyApp(bb::cascades::Application *app);
virtual ~SoundPartyApp() {}
// etc
}
The new virtual ~SoundPartyApp() {} seems to conflict with the function in app.cpp.
Not sure why.
I have commented out the function and now it works... but I guess now I am not properly unallocating the soundmanager from memory.
I can't seem to find any useful threads about how to get beta2 ~destructor functions working in beta3.
Any Ideas?
Solved! Go to Solution.
11-21-2012 07:40 PM
I'm not sure what your error code is, but the virtual destructor should be different in beta 3 vs beta 2. That's a c++ which affect things when they're cast. Google the appropriate use of virtual destructors in cpp.
11-21-2012 08:02 PM
Right, I've done some googling, and am I correct in suggesting that in Beta 2, you defined the destructor in the header file:
~SoundPartyApp();
And then the function in the class file:
SoundPartyApp::~SoundPartyApp()
{
// Destroy the sound manager.
delete mSoundManager;
}But in Beta 3, the virtual destuctor already exists:
virtual ~SoundPartyApp() {}
So I should be able to just expand that, e.g.
virtual ~SoundPartyApp() {
// do some important cleanup
delete mSoundManager;
}
I got the idea from here:
http://stackoverflow.com/questions/461203/when-to-
(see the comment in the code ''// Do some important cleanup')
Looks like this is the place to do it?
11-21-2012 08:34 PM
If you want to relocate the code to the main app, just do this:
virtual ~SoundPartyApp();
And then in the main app do whatever you need to do:
SoundPartyApp::~SoundPartyApp() {
// do some important cleanup
delete mSoundManager;
}
11-21-2012 08:52 PM
Awesome. Worked perfectly, thanks!
Successfully updated some of the other Beta2 sample code now too - thank you.