Results 1 to 4 of 4

Thread: Strange segmentation fault

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Strange segmentation fault

    Hi,

    I have following class:
    Qt Code:
    1. #ifndef NORMALSEARCHWIDGET_H
    2. #define NORMALSEARCHWIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QBoxLayout>
    6. class listBrowserWidget;
    7.  
    8. class normalSearchWidget : public QWidget
    9. {
    10. Q_OBJECT
    11. public:
    12. normalSearchWidget(QWidget *parent = 0);
    13. ~normalSearchWidget();
    14. public slots:
    15. void setLbTbDirection ( QBoxLayout::Direction direction );
    16. private:
    17. listBrowserWidget *lbw1;
    18. listBrowserWidget *lbw2;
    19. QBoxLayout *layout;
    20. };
    21. #endif
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include <QBoxLayout>
    2.  
    3. #include "normalsearchwidget.h"
    4. #include "listbrowserwidget.h"
    5.  
    6. normalSearchWidget::normalSearchWidget(QWidget *parent)
    7. : QWidget(parent)
    8. {
    9. layout = new QBoxLayout( QBoxLayout::TopToBottom );
    10. layout->setMargin( 0 );
    11. layout->setSpacing( 2 );
    12.  
    13. listBrowserWidget *lbw1 = new listBrowserWidget();
    14. listBrowserWidget *lbw2 = new listBrowserWidget();
    15.  
    16. layout->addWidget(lbw1);
    17. layout->addWidget(lbw2);
    18.  
    19. this->setLayout( layout );
    20.  
    21. // Next line works ( same line as in setLbTbDirection(QBoxLayout::Direction direction) )
    22. lbw1->setDirection( QBoxLayout::TopToBottom );
    23.  
    24. // with this line I get and segmentation fault!
    25. setLbTbDirection( QBoxLayout::TopToBottom );
    26. }
    27.  
    28. normalSearchWidget::~normalSearchWidget()
    29. {}
    30.  
    31. void normalSearchWidget::setLbTbDirection ( QBoxLayout::Direction direction )
    32. {
    33. lbw1->setDirection( QBoxLayout::TopToBottom );
    34. }
    To copy to clipboard, switch view to plain text mode 

    As discribed in the commentar, I don't anderstand, why a statement in the constructor works and in a lokal function it causes an segFault. The function itself, without the line, works also perfekt.
    I yet have deleted all generatet files, and have recompiled my program, but the error is still there.

    Thanks for help,
    Lykurg

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange segmentation fault

    Quote Originally Posted by Lykurg
    listBrowserWidget *lbw1 = new listBrowserWidget();
    listBrowserWidget *lbw2 = new listBrowserWidget();
    These are local variables. normalSearchWidget::lbw1 and normalSearchWidget::lbw2 remain uninitialized.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Strange segmentation fault

    Quote Originally Posted by jacek
    These are local variables. normalSearchWidget::lbw1 and normalSearchWidget::lbw2 remain uninitialized.
    Arrgg, you are right, of course! I hate failures like that...

    Thanks
    Lykurg

  4. #4
    Join Date
    Jan 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Strange segmentation fault

    Thanks you too!
    I had the same stupid failure...
    ... because of copy-pasting form Tutorials.

Similar Threads

  1. segmentation fault insert QString in QCombobox
    By regix in forum Qt Programming
    Replies: 16
    Last Post: 8th August 2006, 08:46
  2. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52
  3. (Another) segmentation fault
    By Lebowski in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2006, 06:33
  4. Replies: 2
    Last Post: 25th March 2006, 06:54
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.