Reputation: 31
I have a problem with the layout () in Qt 5. I want to make a dynamic variable dialog. ![enter image description here][1] Below is the code for the constructor:
SortDialog :: SortDialog (QWidget * parent)
: QDialog (parent)
{
setupUi (this);
SecondaryGroupBox-> hide ();
TertiaryGroupBox-> hide ();
layout () -> setSizeConstraint (QLayout :: SetFixedSize);
setColumnRange ('A', 'Z');
}
The project is built successfully, but when you start receiving a signal from the operating system.
Signal: SIGSEGV
Purpose: Segmentation fault
If you delete a row
layout () -> setSizeConstraint (QLayout :: SetFixedSize);
The program works. Please, help me. P.s.:This is an example from the book c++ GUI Programmming with Qt 4 (page 31)
Upvotes: 3
Views: 8442
Reputation: 21
I fixed this with changing in Designer Form. Make sure that the layout in the Qt Designer is good. Especially "Form -> Adjust Size" at the end. (in the book page 33; creating a "Form-> Lay Out in a Grid"). Use the original code from the book.
Upvotes: 0
Reputation: 21
That's because you didn't create a layout.
Go back to designer and click the form and choose lay out in grid.
If you don't do this, the layout would be 0 and the program will crash.
Upvotes: 2
Reputation: 1153
I was having the same problem. I just solved it. Probably you don't want the answer after two years, but I really want to write about this somewhere, because there is nothing about this little issue on the web.
The problem was that Qt Designer didn't generate code to set dialog's layout.
I just opened ui_sortdialog.h and found that out of SortDialog a widget was created. Than with this widget a layout would be created. The layout is called gridLayout_4
, and every widget and layout of the form are added to this one. When I added to function retranslateUi
line SortDialog->setLayout(gridLayout_4);
everything worked. Generated code created layout and did everything what needed to be done, but it left SortDialog without any reference to the layout, therefore layout()
returned zero.
Upvotes: 4
Reputation: 1344
You have to create a layout, like QVBoxLayout.
QVBoxLayout *layout = new QVBoxLayout;
layout->setSizeConstraint (QLayout :: SetFixedSize);
setLayout(layout);
Upvotes: 0