PDA

View Full Version : Public function called on MDISubWindow ignores code



ad5xj
24th February 2009, 03:54
I have created several MDISubWindows in an MDIArea.

I call a public function on one of the MDISubWindow children from the MDI MainWindow. Objects created by code in the MDISubWindow constructor are not treated as members of the window. In fact the objects in the MDISubWindow needed, cause a seg fault when used from the MDI MainWindow. This does not happen when code in the MDISubWindow uses the same objects. What gives?

jryannel
24th February 2009, 08:47
Can you provide a small example code (isolating the cause)? It's difficult for me to understand what happens here.

- Juergen

ad5xj
24th February 2009, 17:29
Ok, here are some code snippets from the application. . .

In MDI MainWindow:


void MainWindow::createMdiPrevQSOs()
{
// show the window
mdiPrev = new mdiPrevQSOs;
mdiArea->addSubWindow(mdiPrev);
mdiPrev->show();
}

long after creation:


void MainWindow::slotUpdatePrev()
{
QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
foreach (QMdiSubWindow *window, mdiArea->subWindowList())
{
if (window->windowTitle().startsWith(tr("Previous"),Qt::CaseInsensitive))
{
mdiPrevQSOs *child = qobject_cast<mdiPrevQSOs *>(window);
if (child->findPrev()) // (debug shows seg fault previous step is here)
{
. . .
}
}
}
. . .
}

the MDISubWindow has a list Widget that is filled by the called function.

mdiPrevQSOs constructor:


mdiPrevQSOs::mdiPrevQSOs(QWidget *parent) : QDialog(parent)
{
setAttribute(Qt::WA_DeleteOnClose);
. . .
widget = new QWidget(this);
widget->setObjectName(QString::fromUtf8("widget"));
. . .
listView = new QTreeView(widget);
listView->setObjectName(QString::fromUtf8("listView"));
}

the public function called:


bool mdiPrevQSOs::findPrev()
{
. . .
// create a query . . .
// create a QStandardItemModel for the tree view. . .
// fill the model with data from the query . . .
. . .
// (this line crashes with a seg fault)
listView->setModel(s_model); // the tree view created in the constructor
. . .
}