Qt-interest Archive, July 2007
Please help understanding QScriptEngine::newQMetaObject
Message 1 in thread
In the tetrix example I cas see that the Qt namespace including all enums is
made available to the script engine as:
struct QtMetaObject : private QObject
{
public:
static const QMetaObject *get()
{ return &static_cast<QtMetaObject*>(0)->staticQtMetaObject; }
};
....
QApplication app(argc, argv);
QScriptEngine engine;
QScriptValue Qt = engine.newQMetaObject(QtMetaObject::get());
Qt.setProperty("App", engine.newQObject(&app));
engine.globalObject().setProperty("Qt", Qt);
I have a hard time understanding the get() function of the struct. Could
some QtScript guru (Kent?) please explain it?
--
[ signature omitted ]
Message 2 in thread
Hi,
is it only me, or does anybody else experiences irregular segfaults
with QFileDialog? I use the static getExistingDirectory method. Very
often when I create a new directory and almost always when I drag/drop
a new folder into the shortcut list my program segfaults.
The only non-standard thing with getExistingDirectory is that it is
called from a slot within a modal QDialog. It crashes when my dialog
exits.
Below I have a part of backtrace of the last core. I suppose the
problem is this=0x0 when the modal eventloop exits. Using drag and drop
in a modal QFileSelector, which was called from a modal QDialog seems
to be evil.
I am using 4.3.0 on Linux.
Any ideas?
Program terminated with signal 11, Segmentation fault.
#0 QEventLoop::exit (this=0x0, returnCode=0)
at ../../include/QtCore/../../src/corelib/kernel/qeventloop.h:38
38 Q_DECLARE_PRIVATE(QEventLoop)
(gdb) bt
#0 QEventLoop::exit (this=0x0, returnCode=0)
at ../../include/QtCore/../../src/corelib/kernel/qeventloop.h:38
#1 0x00002ab22d988882 in QDragManager::eventFilter (this=0x6a6a40,
o=<value optimized out>, e=<value optimized out>)
at kernel/qdnd_x11.cpp:1238
#2 0x00002ab22d9261b0 in QApplicationPrivate::notify_helper (
this=<value optimized out>, receiver=0x174ce70, e=0x7fff7daa6b60)
at kernel/qapplication.cpp:3499
#3 0x00002ab22d92900e in QApplication::notify (this=0x7fff7daa87e0,
receiver=0x174ce70, e=0x7fff7daa6b60) at
kernel/qapplication.cpp:3237
#4 0x00002ab22f263390 in QCoreApplication::notifyInternal (
this=0x7fff7daa87e0, receiver=0x174ce70, event=0x7fff7daa6b60)
at kernel/qcoreapplication.cpp:509
#5 0x00002ab22d97c6cf in QETWidget::translateMouseEvent
(this=0x174ce70,
event=<value optimized out>)
at
../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:189
#6 0x00002ab22d97b92c in QApplication::x11ProcessEvent (this=0x135,
event=0x7fff7daa70b0) at kernel/qapplication_x11.cpp:3009
--
[ signature omitted ]
Message 3 in thread
On Thursday 12 July 2007 10:03:04 Guido Seifert wrote:
> Hi,
> is it only me, or does anybody else experiences irregular segfaults
> with QFileDialog? I use the static getExistingDirectory method. Very
> often when I create a new directory and almost always when I drag/drop
> a new folder into the shortcut list my program segfaults.
Yes, this was reported and was fixed, but unfortunetly was accidently not
intigrated into 4.3.0. If you use gui/dialogs/qfilesystemmodel and
gui/dialogs/qfiledialog from snapshots this will be resolved.
-Benjamin Meyer
--
[ signature omitted ]
Message 4 in thread
>
> Yes, this was reported and was fixed, but unfortunetly was accidently not
> intigrated into 4.3.0. If you use gui/dialogs/qfilesystemmodel and
> gui/dialogs/qfiledialog from snapshots this will be resolved.
No problem. I can wait for 4.3.1 :-)
Thanks,
Guido
--
[ signature omitted ]
Message 5 in thread
Seneca wrote:
>In the tetrix example I cas see that the Qt namespace including all enums is
>made available to the script engine as:
>
>struct QtMetaObject : private QObject
>{
>public:
> static const QMetaObject *get()
> { return &static_cast<QtMetaObject*>(0)->staticQtMetaObject; }
>
>
[...]
>};
>I have a hard time understanding the get() function of the struct. Could
>some QtScript guru (Kent?) please explain it?
>
>
Hi Seneca,
Ah, looks like you've found the winner in the "Most obscure piece of
code in a Qt example" category. ;-) It's just a common trick to use when
you have a class with a protected (static) member (e.g.
QObject::staticQtMetaObject) that you want to get access to from outside
the (sub)class. Maybe adding a QScriptEngine::qtNamespaceObject()
function wouldn't be a horribly bad thing to do; then you wouldn't have
to copy and paste the above cursed code if you wanted the Qt namespace
in your own app, for example.
Regards,
Kent
--
[ signature omitted ]