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. Resize causes segmentation fault
Qt 6.11 is out! See what's new in the release blog

Resize causes segmentation fault

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.9k 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    Hello, here's a sample of my code:

    class Base : public QMainWindow
    {
        Q_OBJECT
        
        protected:
        
            QWidget*   centralWidget;
            QTextEdit* foo;
            // ...
    };
    

    Base's constructor is implemented as follows:

    Base::Base(void) :
        QMainWindow(),
        centralWidget(new QWidget()),
        foo(new QTextEdit(centralWidget)),
        // ...
    {
        QMainWindow::setCentralWidget(centralWidget);
        // ...
    }
    

    Now, here's a derived class.

    class Derived : public Base
    {
        Q_OBJECT
    
        // ...
    };
    

    Derived's constructor is implemented as follows:

    Derived::Derived(void) :
        Base(),
        // ...
    {
        // ...
        foo->resize(436, 124);
        // ...
    }
    

    Unfortunately, foo->resize(436, 124); often causes a segmentation fault. I say often because it sometimes (althrough rarely) doesn't... If that helps, here's the relevant track:

    /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZNK7QWidget20testAttribute_helperEN2Qt15WidgetAttributeE+0x1e)[0x7fd396049aae]
    /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN7QWidget12setAttributeEN2Qt15WidgetAttributeEb+0x167)[0x7fd396051667]
    /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN7QWidget6resizeERK5QSize+0x1d)[0x7fd396056d2d]
    

    Any insight?

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

      Hi,

      Out of curiosity, why resize that QTextEdit and not set it as central widget ?

      Also, which version of Qt are you using ?

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

      P 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Out of curiosity, why resize that QTextEdit and not set it as central widget ?

        Also, which version of Qt are you using ?

        P Offline
        P Offline
        Pippin
        wrote on last edited by Pippin
        #3

        @SGaist I'm sorry but I don't get your question. There are many Widgets on that window, and I want this QTextEdit to have that particular size (, at that particular place).

        I believe that this is Qt 5.6

        Edit: If I swap this line with foo->move(...); then I get a segmentation fault there. It looks like whatever member function will cause a segfault.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pippin
          wrote on last edited by
          #4

          Solved: It looks like I forgot to delete a member variable inside Derived, whose name was... foo. I do apologize for wasting everyone's time...

          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