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. setStyle -> USER Objects leak
Forum Updated to NodeBB v4.3 + New Features

setStyle -> USER Objects leak

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.0k Views 2 Watching
  • 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.
  • K Offline
    K Offline
    KIT2005
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you using your custom style ?
      Why are you constantly deleting/creating that toolbar ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        @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.

        K 1 Reply Last reply
        1
        • K Offline
          K Offline
          KIT2005
          wrote on last edited by
          #4

          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

          mrjjM 1 Reply Last reply
          0
          • K KIT2005

            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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @KIT2005
            Hi
            but is dtor called on each time you switch ?
            also the code shown has a local style
            MyProxyStyle *proxyStyle = ... // local

            so in dtor
            if(proxyStyle )
            {
            delete proxyStyle ;

            what style is that ? seems not to be the one you new.

            K 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Your if statement won't help, you are creating a local variable named proxyStyle so unless you run out of memory, it will alway be true as the allocation will succeed.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • mrjjM mrjj

                @KIT2005
                Hi
                but is dtor called on each time you switch ?
                also the code shown has a local style
                MyProxyStyle *proxyStyle = ... // local

                so in dtor
                if(proxyStyle )
                {
                delete proxyStyle ;

                what style is that ? seems not to be the one you new.

                K Offline
                K Offline
                KIT2005
                wrote on last edited by
                #7

                @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 );

                1 Reply Last reply
                0
                • mrjjM mrjj

                  @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.

                  K Offline
                  K Offline
                  KIT2005
                  wrote on last edited by
                  #8

                  @mrjj

                  Thanks for the hint"QWidgets:.setStyle, ownership is not transferred". It helped me fix the issue.

                  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