Safely destroy widget

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Safely destroy widget

Postby sramp » Mon Mar 24, 2014 11:42 pm

Hello,
in my script I create a widget with WidgetFactory.createWidget. It's a window with buttons, labels, edit fields and a table.
Since the script is called repeatedly , when the user close the window I prefer to destroy it in this way :
Code: Select all
this.mw.close();
this.mw.destroy();

After this, sometimes, the application crash.
As usual in my development Mac the crash happens very rarely.
Conversely my beta tester reports several crashes.
The debugger is not invoked, so no help from it.
At the moment I'm trying to use the Qt.WA_DeleteOnClose attribute instead of destroy :

Code: Select all
 this.mw.setAttribute(Qt.WA_DeleteOnClose,true);


Please, which is the safer way to destroy the window ?
Thank you
sramp

ps Here the diagnostic log :

Code: Select all
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   QtGui                               0x0366a6cf QWidgetPrivate::childAt_helper(QPoint const&, bool) const + 31
1   QtGui                               0x0366a813 QWidget::childAt(QPoint const&) const + 35
2   QtGui                               0x035cd83d QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() + 5181
3   QtGui                               0x035d1237 QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool() + 20023
4   QtGui                               0x035bfb23 QWidget::grabMouse(QCursor const&) + 12467
5   com.apple.AppKit                    0x926b7ecb -[NSWindow sendEvent:] + 7787
6   QtGui                               0x035c5cec QMacInputContext::reset() + 24012
7   com.apple.AppKit                    0x92650f77 -[NSApplication sendEvent:] + 4788
8   QtGui                               0x035cae62 QMacInputContext::reset() + 44866
9   com.apple.AppKit                    0x925e2b21 -[NSApplication run] + 1007
10  QtGui                               0x035d617a QDesktopWidget::resizeEvent(QResizeEvent*) + 12890
11  QtCore                              0x03322681 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 65
12  QtCore                              0x03322a5a QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 314
13  QtCore                              0x03324f86 QCoreApplication::exec() + 182
14  libqtscript_core.dylib              0x0ed004e4 _ZL37qtscript_QCoreApplication_static_callP14QScriptContextP13QScriptEngine + 2788
15  QtScript                            0x03116fd8 QScriptable::QScriptable() + 3256
16  QtScript                            0x0302ed10 0x2f5d000 + 859408
17  QtScript                            0x03003eb4 0x2f5d000 + 683700
18  ???                                 0x1023ae07 0 + 270773767
19  QtScript                            0x02fbb457 0x2f5d000 + 386135
20  QtScript                            0x02fbb751 0x2f5d000 + 386897
21  QtScript                            0x030ede46 QScriptEngine::setGlobalObject(QScriptValue const&) + 1174
22  QtScript                            0x030f57f1 QScriptEngine::evaluate(QString const&, QString const&, int) + 801
23  libqcadecmaapi.dylib                0x00049213 RScriptHandlerEcma::eval(QString const&, QString const&) + 67
24  libqcadecmaapi.dylib                0x000417f3 RScriptHandlerEcma::doScript(QString const&, QStringList const&) + 915
25  libqcadcore.dylib                   0x0131cc32 RScriptHandler::init(QString const&, QStringList const&) + 450
26  org.qcad                            0x0000b23b main + 2139
27  org.qcad                            0x0000a4f9 _start + 208
28  org.qcad                            0x0000a428 start + 40
sramp
Active Member
 
Posts: 26
Joined: Mon Dec 02, 2013 4:15 pm

Re: Safely destroy widget

Postby andrew » Tue Mar 25, 2014 9:12 am

If a widget has a parent (recommended for all widgets except top level widgets), it will be deleted automatically with its parent.

Top level widgets typically have the Qt.WA_DeleteOnClose flag set.
User avatar
andrew
Site Admin
 
Posts: 2756
Joined: Fri Mar 30, 2007 6:07 am

Re: Safely destroy widget

Postby sramp » Wed Mar 26, 2014 12:48 pm

Thanks Andrew,
I confirm that setting the Qt.WA_DeleteOnClose attribute fix the problem.
sramp
sramp
Active Member
 
Posts: 26
Joined: Mon Dec 02, 2013 4:15 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 1 guest