[Qt-interest] Layout segmentation fault

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Mar 4 20:35:47 CET 2009


Nicholas Torr wrote on Tuesday, March 03, 2009 10:31 AM:

> ..
> this class is a subclass of qmainwindow, with this function being

"LeftWindow" is a subclass of QMainWindow, right?

> called from the main immediately after construction 

Exactly WHEN is SetupWindow() called? And WHO calls it? What does "from the main" mean? "main" what? The 

  int main(int argc, char **argv) {}

function?

See below.
> 
> void LeftWindow::SetupWindow()
> {
>     if (layout() != 0)
>         delete layout();
>     else
>         qDebug() << "No Layout to Destroy.";
>     QGridLayout* gridLayout = new QGridLayout(this); }
> 
> this causes an immediate segmentation fault. Any ideas?

WHERE exactly does the segmentation fault occur, at what line? (use a debugger). Assuming that you call the SetupWindow() method from the c'tor of the QMainWindow subclass itself (Again, "LeftWindow" is the QMainWindow subclass?), it COULD be that the widget is not fully initialised yet, and hence the method layout() returns garbage: something != 0.

And hence delete fails.

What does your c'tor look like? Maybe you forgot to initialise the superclass first? Does it look something like this?

LeftWindow::LeftWindow(QWidget *parent)
: QMainWindow(parent) // did you initialise the superclass? {
  ...
  // at this point the superclass should actually be fully initialised and
  // layout() should return a "valid" value (I would assume 0)
  this->SetupWindow();
  ...
}

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list