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. QWidget::style crashes with "Read Access Violation"

QWidget::style crashes with "Read Access Violation"

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.5k 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.
  • A Offline
    A Offline
    ajaxcrypto
    wrote on last edited by
    #1

    I have created a custom control (derived from QLabel), and overriden the mouseReleaseEvent where I am emitting certain signals and I need to repolish the widget so that some of the dynamic properties based QSS style gets reflected.

    I have a repolish method which is declared as:

    void MyWidget::repolish()
    {
        auto style = this->style();
        if (style != nullptr)
        {
            style->unpolish(this);
            style->polish(this);
        }
    }
    

    The mouse release event handler is:

    void MyWidget::mouseReleaseEvent(QMouseEvent * event)
    {
        if (isEnabled())
        {
            setPressed(false);
            if (m_canBeToggled)
            {
                setChecked(!m_checked);
            }
            else
            {
                emit clicked();
            }
            repolish();
        }
    }
    

    I get a "Read Access Violation" right at the statement auto style = this->style();. Why is this the case?

    The attached slot is:
    QObject::connect(mywidget, &MyWidget::clicked, [...]{ ... });

    jsulmJ 1 Reply Last reply
    0
    • A ajaxcrypto

      I have created a custom control (derived from QLabel), and overriden the mouseReleaseEvent where I am emitting certain signals and I need to repolish the widget so that some of the dynamic properties based QSS style gets reflected.

      I have a repolish method which is declared as:

      void MyWidget::repolish()
      {
          auto style = this->style();
          if (style != nullptr)
          {
              style->unpolish(this);
              style->polish(this);
          }
      }
      

      The mouse release event handler is:

      void MyWidget::mouseReleaseEvent(QMouseEvent * event)
      {
          if (isEnabled())
          {
              setPressed(false);
              if (m_canBeToggled)
              {
                  setChecked(!m_checked);
              }
              else
              {
                  emit clicked();
              }
              repolish();
          }
      }
      

      I get a "Read Access Violation" right at the statement auto style = this->style();. Why is this the case?

      The attached slot is:
      QObject::connect(mywidget, &MyWidget::clicked, [...]{ ... });

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ajaxcrypto Do you mean you get this error at runtime?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ajaxcrypto
        wrote on last edited by
        #3

        Yes at runtime, I figured out the runtime error part. The parent widget was being deleted on the clicked signal emission. Because repolishing happens after the signal, so a repolish on an invalid object was being called.

        P.S. - The forum is very prompt!

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

          Hi,

          Why was the parent deleted ?

          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
          0
          • A Offline
            A Offline
            ajaxcrypto
            wrote on last edited by
            #5

            It was because of how the slot was written, which calls some functions which ultimately leads to the deletion. I am now repolishing before emitting the signal because that behavior is required.

            kshegunovK 1 Reply Last reply
            0
            • A ajaxcrypto

              It was because of how the slot was written, which calls some functions which ultimately leads to the deletion. I am now repolishing before emitting the signal because that behavior is required.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              You should use QObject::deleteLater in this case which will take care of the deletion in a safe manner.

              Read and abide by the Qt Code of Conduct

              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