PDA

View Full Version : SetSizeConstraint gives Segmentation fault.



indy
11th October 2007, 21:51
I am reading the book "C++ GUI programming with QT4" and I have a problem with the example of the Shape-Changing dialogs in chapter 2. I followed the tutorial by designing the GUI with designer and building the project in Eclipse. Everything compiles fine. The problem is with the constructor of the dialog box.



SortDialog::SortDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);

secondaryGroupBox->hide();
tertiaryGroupBox->hide();
layout()->setSizeConstraint(QLayout::SetFixedSize);
setColoumnRange('A', 'Z');
}
When I add the line
layout()->setSizeConstraint(QLayout::SetFixedSize); the project compiles but when I try to run the executable I get Segmentation fault. Without that line the program runs ok but of course the dialog doesn't resize.

I am using Linux with KDE. Can anyone explain what is wrong please?

jacek
11th October 2007, 22:06
Do you have a top-level layout on that dialog?

indy
11th October 2007, 22:38
Thank you, that was it. I did a Layout->Layout in a grid and then it ran fine. The strange thing is that I could not reproduce the same layout using designer. I did it with the Qt plugin for Eclipse. I hope with experience will avoid such mistakes in the future but is there any way to ensure that there is always a top level layout?

jacek
11th October 2007, 23:47
is there any way to ensure that there is always a top level layout?
You don't have to use layouts, so Qt Designer doesn't know whether it's OK or not if you did't add the top-level layout. Although it warns you about a missing top-level layout when you try to save an .ui file with spacers.

I simply test all m .ui files before saving them.