Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved setStyle -> USER Objects leak

    General and Desktop
    3
    8
    603
    Loading More Posts
    • 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
      KIT2005 last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • mrjj
          mrjj Lifetime Qt Champion last edited by 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 1 Reply Last reply Reply Quote 1
          • K
            KIT2005 last edited by

            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

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @KIT2005 last edited by

              @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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 1
                • K
                  KIT2005 @mrjj last edited by

                  @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 Reply Quote 0
                  • K
                    KIT2005 @mrjj last edited by

                    @mrjj

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

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post