Public function called on MDISubWindow ignores code
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?
Re: Public function called on MDISubWindow ignores code
Can you provide a small example code (isolating the cause)? It's difficult for me to understand what happens here.
- Juergen
Re: Public function called on MDISubWindow ignores code
Ok, here are some code snippets from the application. . .
In MDI MainWindow:
Code:
void MainWindow::createMdiPrevQSOs()
{
// show the window
mdiPrev = new mdiPrevQSOs;
mdiArea->addSubWindow(mdiPrev);
mdiPrev->show();
}
long after creation:
Code:
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:
Code:
{
setAttribute(Qt::WA_DeleteOnClose);
. . .
widget
->setObjectName
(QString::fromUtf8("widget"));
. . .
listView
->setObjectName
(QString::fromUtf8("listView"));
}
the public function called:
Code:
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
. . .
}