Mdichild related problem
-
Hi,
I got a mdichild class (derived from QPlainTextEdit).
When I try to "play" with it (using setTabStopWidth ortrying to move its cursor for example).
It crashed in QScopedPointer.h in the function@ inline T *data() const
{
return d; <============ crash here with an invalid "this" value .
}@
the crash only appends if my mdichild already exists (i.e. if found in mdiArea->subWindowList() );
When the mdichild does not exist yet and just created and add with mdiArea->addSubWindow(child); evrything isIs it a thread related problem ?
Do i need to do something special (like waiting for the mdichild to show up) before trying to work with it ?Any help will be appreciated.
Thanks in advance -
Please give us a bit more information.
- Are you working with worker threads?
- What do they do?
-
No, I don't use worker threads at all.
I started with this sample :
"http://qt-project.org/doc/qt-4.8/mainwindows-mdi.html":http://qt-project.org/doc/qt-4.8/mainwindows-mdi.htmlAnd I'm trying to set the tab width here :
@ void MainWindow::open()
{
QString fileName = QFileDialog::getOpenFileName(this);
if (!fileName.isEmpty()) {
QMdiSubWindow *existing = findMdiChild(fileName);
if (existing) {
mdiArea->setActiveSubWindow(existing);
existing->MyFunctionToSetTabWidth(); <---Here
return;
}MdiChild *child = createMdiChild(); if (child->loadFile(fileName)) { statusBar()->showMessage(tr("File loaded"), 2000); child->show(); } else { child->close(); } }
}
@ -
Hm,
in general, this function looks good. Maybe it's in the sourroundings somewhere. Did you debug the whole thing and check, whether existing points to a valid object? -
Thanks a lot, you were right, it was in the surroundings.
It was a bad cast. findMdiChild returns a QMdiSubWindow and not directly a widget. The solution was to cast the widget and not directly the subwindow like this :@ QMdiSubWindow *subw = findMdiChild(fileName);
if (subw != NULL)
{
existing = qobject_cast<MdiChild *> (subw->widget());
}@