Resize causes segmentation fault



  • 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?


  • Lifetime Qt Champion

    Hi,

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

    Also, which version of Qt are you using ?



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.