Solved setStyle -> USER Objects leak
-
Re: Change the size of ">>" arrow when a QToolBar is too small
It is possible to change the size of the >> extension button in the Toolbar, by subclassing QProxyStyle as shown below.
virtual int MyProxyStyle::pixelMetric(PixelMetric pm, const QStyleOption* option, const QWidget* widget) const
{
if( pm == QStyle::PM_ToolBarExtensionExtent )
return XXX; // width for horizontal, height for vertical toolbars
return QProxyStyle::pixelMetric(pm, option, widget);
}But setStyle() using MyProxyStyle increases the USER Objects which eventually leads to crash after many days of continuously creation and deletion of Toolbar.
Does setStyle() has memory leak?
-
Hi,
How are you using your custom style ?
Why are you constantly deleting/creating that toolbar ? -
@KIT2005 said in setStyle -> USER Objects leak:
Does setStyle() has memory leak?
Well, on QWidgets:.setStyle, ownership is not transferred, so if you new the style each time you assign it, and never delete the last one, you will leak.
-
Hi,
I have many pages with different controls. One such control has the toolbar and so when I switch from one page to another having the control with toolbar, the USER objects increases.
During the creation of Toolbar I have used
MyProxyStyle *proxyStyle = new MyProxyStyle ();
if(proxyStyle )
setStyle(proxyStyle );In the destructor, I have used
if(proxyStyle )
{
delete proxyStyle ;
proxyStyle = NULL;
}I have concluded that by commenting the line setStyle() the USER objects are not increasing. So I am not sure if there is a leak with QT or i am doing something wrong
-
@KIT2005
Hi
but is dtor called on each time you switch ?
also the code shown has a local style
MyProxyStyle *proxyStyle = ... // localso in dtor
if(proxyStyle )
{
delete proxyStyle ;what style is that ? seems not to be the one you new.
-
Your
if
statement won't help, you are creating a local variable namedproxyStyle
so unless you run out of memory, it will alway be true as the allocation will succeed. -
@mrjj
I am doing the page switch at regular interval and my dtor is also called everytime.MyProxyStyle *proxyStyle = ../ is not local but a member variable. I typed the statement to show the creation part and its a typo error.
It is actually
proxyStyle = new MyProxyStyle ();
if(proxyStyle )
setStyle(proxyStyle ); -
Thanks for the hint"QWidgets:.setStyle, ownership is not transferred". It helped me fix the issue.