[Qt-qml] QDeclarativeView::setObjectOwnership

2010-11-29 Thread Girish Ramakrishnan
Hi,
QDeclarativeView::setObjectOwnership doesn't seem to be working as I
would expect. Maybe I am reading the documentation wrong.

In essence, I have a
Q_INVOKABLE QObject *create() {
Object *o = new Object;
o-setObjectName(object x);
QDeclarativeEngine::setObjectOwnership(o, QDeclarativeEngine::CppOwnership);
return o;
}

I call the above function from QML and despite the ownership being set
to CppOwnership, the above objects gets deleted anyway.

If you want full compilable code, it's here -
http://pastebin.com/ffqmxHy6. Keep clicking on the rectangle to create
new objects. Then close the app, all the created objects gets deleted
(I thought setting CppOwnership will make qml not delete the objects).

Girish
___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] QDeclarativeView::setObjectOwnership

2010-11-29 Thread Girish Ramakrishnan
Hi,
Replying to myself.

On Mon, Nov 29, 2010 at 3:08 PM, Girish Ramakrishnan
gir...@forwardbias.in wrote:
 Hi,
 QDeclarativeView::setObjectOwnership doesn't seem to be working as I
 would expect. Maybe I am reading the documentation wrong.

 In essence, I have a
 Q_INVOKABLE QObject *create() {
    Object *o = new Object;
    o-setObjectName(object x);
    QDeclarativeEngine::setObjectOwnership(o, 
 QDeclarativeEngine::CppOwnership);
    return o;
 }

 I call the above function from QML and despite the ownership being set
 to CppOwnership, the above objects gets deleted anyway.

 If you want full compilable code, it's here -
 http://pastebin.com/ffqmxHy6. Keep clicking on the rectangle to create
 new objects. Then close the app, all the created objects gets deleted
 (I thought setting CppOwnership will make qml not delete the objects).


Gregory pointed out on irc that I need to prove that qml is deleting
it. So here's my gdb session:

Creating new  Object(0x85c5f0) // Object gets created
3

Breakpoint 1, QObject::deleteLater (this=0x60cf40) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
2123QCoreApplication::postEvent(this, new
QEvent(QEvent::DeferredDelete)); // this is the delete of the view
(gdb) c
Continuing.

Breakpoint 1, QObject::deleteLater (this=0x85c5f0) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
2123QCoreApplication::postEvent(this, new
QEvent(QEvent::DeferredDelete)); // delete of the object (see pointer
value)
(gdb) bt
#0  QObject::deleteLater (this=0x85c5f0) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:2123
#1  0x77a30ff7 in ObjectData::~ObjectData (this=0x85b170,
__in_chrg=value optimized out)
at 
/home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeobjectscriptclass.cpp:73
#2  0x77460ac1 in
QScript::DeclarativeObjectDelegate::~DeclarativeObjectDelegate
(this=0x86e7a0, __in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptdeclarativeobject.cpp:56
#3  0x7744703e in QScriptObject::Data::~Data (this=0x797a10,
__in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:42
#4  0x774471b4 in QScriptObject::~QScriptObject
(this=0x7fffe13c4d40, __in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/script/bridge/qscriptobject.cpp:52
#5  0x7734b52e in QTJSC::Heap::freeBlocks (this=0x7fffec046a18)
at 
/home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:349
#6  0x7734af21 in QTJSC::Heap::destroy (this=0x7fffec046a18)
at 
/home/girish/Qt/qt-4.7/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Collector.cpp:199
#7  0x7741f7a8 in QScriptEnginePrivate::~QScriptEnginePrivate
(this=0x8025b0, __in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1028
#8  0x7520e0aa in QScopedPointerDeleterQObjectData::cleanup
(pointer=0x8025b0)
at 
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#9  0x7526ede5 in QScopedPointerQObjectData,
QScopedPointerDeleterQObjectData ::~QScopedPointer (this=0x802098,
__in_chrg=value optimized out)
at 
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#10 0x752669ab in QObject::~QObject (this=0x802090,
__in_chrg=value optimized out) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#11 0x77424d38 in QScriptEngine::~QScriptEngine
(this=0x802090, __in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/script/api/qscriptengine.cpp:1980
#12 0x77956da6 in
QDeclarativeScriptEngine::~QDeclarativeScriptEngine (this=0x802090,
__in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:382
#13 0x779586a6 in
QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate (this=0x801f80,
__in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:431
#14 0x7520e0aa in QScopedPointerDeleterQObjectData::cleanup
(pointer=0x801f80)
at 
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:62
#15 0x7526ede5 in QScopedPointerQObjectData,
QScopedPointerDeleterQObjectData ::~QScopedPointer (this=0x801388,
__in_chrg=value optimized out)
at 
../../include/QtCore/../../../../qt-4.7/src/corelib/tools/qscopedpointer.h:100
#16 0x752669ab in QObject::~QObject (this=0x801380,
__in_chrg=value optimized out) at
/home/girish/Qt/qt-4.7/src/corelib/kernel/qobject.cpp:963
#17 0x77958ed1 in QDeclarativeEngine::~QDeclarativeEngine
(this=0x801380, __in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/declarative/qml/qdeclarativeengine.cpp:555
#18 0x77839804 in
QDeclarativeViewPrivate::~QDeclarativeViewPrivate (this=0x7ed250,
__in_chrg=value optimized out)
at /home/girish/Qt/qt-4.7/src/declarative/util/qdeclarativeview.cpp:135
#19

Re: [Qt-qml] Screen dimensions

2010-11-24 Thread Girish Ramakrishnan
You can expose QDesktopWidget::screenGeometry() to the QML engine and
then access it from the QML. Something like,

engine-rootContext()-setContextProperty(screen,
QApplication::desktop()-screenGeometry());

And then screen.width and screen.height can be used in the QML.

Girish

On Wed, Nov 24, 2010 at 3:56 PM, Mark Constable ma...@renta.net wrote:
 How would I determine the screen dimensions of the
 device being used from within QML code?

 Any source examples available?
 ___
 Qt-qml mailing list
 Qt-qml@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-qml

___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] Modal dialogs in QML?

2010-11-24 Thread Girish Ramakrishnan
Hi,

On Wed, Nov 24, 2010 at 10:05 AM, Bart Kelsey elba...@gmail.com wrote:
 Greets!

 Is there any way to create a modal dialog in QML, such that mouse input
 outside of the dialog box is blocked?  I've tried making a dialog with a
 MouseArea under it (which would catch mouse input and do nothing with it),
 but I can't seem to figure out how to make the MouseArea fill the entire
 screen.  Any ideas?


Conceptually something like,
// main.qml
Item {

Dialog { // make Dialog a direct child of the main window
anchors.fill: parent; // Dialog spans the entire window
MouseArea { anchors.fill: parent; onClicked: opacity = 0; } //
handle outside clicks
Rectangle { // the dialogs content
anchors.centerIn: parent
MouseArea { anchors.fill: parent; } // absorb clicks in
the content area so that it won't close the dialog
...your dialog's widgets...
}
}
}

You can expand on the above idea to use a Loader so that the Dialog
gets created lazily.

Girish

___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] C++ MyClass to detect child added/removed from QML

2010-11-24 Thread Girish Ramakrishnan
Hi Charley,

On Wed, Nov 24, 2010 at 7:42 PM, Charley Bay charleyb...@gmail.com wrote:
 snip, detect parent/child changes from QML in C++

 Martin spaketh:

 QGraphicsItem::itemChange() may do what you want:



 http://doc.qt.nokia.com/4.7-snapshot/qgraphicsitem.html#itemChange

 Works great!  Thanks!

 Related question:  Now that I'm in the QGraphicsItem world, which is *not* a
 QObject with properties, how does QML expose attributes (since those are
 *all* properties based)?


QML works with properties exposed through the metaobject system
(Q_PROPERTY). So, items have to be extend QObject at some point.
AFAIK, QML supports properties exposed through QObject and user
visible items must be QGraphicsObject or QDeclarativeItem (there are
restrictions like the component's root item must be a QDeclarative
item etc).

 For example, the QGraphicsItem::boundingRect() is always (0,0,-1,-1), even
 though the referenced QML component *has* width and height.  Similarly, the
 QGraphicsItem::opaqueArea()::boundingRect() is always (0,0,0,0).  Does the
 QGraphicsItem have *any* opinion about or state from attributes in the QML
 element?  (e.g., what attributes can I trust in the QGraphicsItem as being
 those used by the QML element?)


QDeclarativeView builds on QGraphicsView. So,
QGraphicsItem::boundingRect is still very much used. For a component,
the QGraphicsItem of the component will return the (0, 0, width,
height), so I think your testing above is probably incorrect. I think
opaqueArea is used only for obscurity detection which is not used in
QML and thus left unimplemented.

 What is the intended mechanism by which I interrogate the QGraphicsItem?

As I understand, all QGraphicsItem API should still work as expected
for QML items.

 (Is the expectation that the user will merely attempt to downcast to
 QGraphicsObject or QDeclarativeItem, handling the scenarios where it is not
 that type?)  For examle, I *assume* that the MouseArea will trigger child
 notification, but it is not a QDeclarativeItem.  In contrast, a Rectangle{}
 or Text{} trigger child notification, and happen to be QDeclarativeItem
 instances.


MouseArea is a QDeclarativeItem. Think of it as a transparent
overlay child item that positions itself over the parent. I do not
know why it does not trigger child notifications.

Girish

___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] C++ MyClass to detect child added/removed from QML

2010-11-24 Thread Girish Ramakrishnan
Hi,

On Thu, Nov 25, 2010 at 2:55 AM, Charley Bay charleyb...@gmail.com wrote:
 I confirmed that these *do not* work for me:

 ...with a Text { width: 50; height: 20 } on the QML side,

 QGraphicsItem::boundingRect() // ALWAYS RETURNS QRectF(0,0,-1,-1)
 QGraphicsItem::opaqueArea().boundingRect() // ALWAYS RETURNS QRectF(0,0,0,0)

 ...however, after casting the QGraphicsItem* to a QObject*, I can correctly
 extract my width and height properties.

 So, my current conclusion is that I have *no* useful properties in
 QGraphicsItem (and must cross-cast it to something I can use).

boundingRect() works as I would expect. Can you provide some sample code?

Rectangle {
width: 300
height: 300
objectName: rect

Text {
objectName: text
text: foo
}
}


QDeclarativeItem *rect = qobject_castQDeclarativeItem *(view-rootObject());
qDebug()  rect-boundingRect();
QDeclarativeItem *text = rect-findChildQDeclarativeItem *(text);
qDebug()  text-boundingRect();

Output:
QRectF(0,0 300x300)
QRectF(0,0 24x17)

The first one is the rect of the top level item (and it matches what I
set in qml) and the second one is the text item's computed
width/height. So, the values are as I would expect.

Girish
___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] Mouse wheel events in QML

2010-11-20 Thread Girish Ramakrishnan
See http://bugreports.qt.nokia.com/browse/QTBUG-7369. In short,
Flickable supports it but not MouseArea.

Girish

On Sat, Nov 20, 2010 at 9:17 PM, Jerzy Chalupski
jerzy.chalup...@gmail.com wrote:
 I can't find any mouse wheel events handler. Am I selectively blind or
 are mouse wheel events not supported by QML?
 ___
 Qt-qml mailing list
 Qt-qml@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-qml

___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml


Re: [Qt-qml] Exporting enums to QML

2010-11-19 Thread Girish Ramakrishnan
Hi,
Create a QObject subclass with the enums and register the class using
qmlRegisterUncreatableType.

Girish

On Sat, Nov 20, 2010 at 12:13 AM,  jerome.pas...@nokia.com wrote:
 Hello,

 I know there is no enum reserved keyword in JavaScript, but what is the 
 preferred way to expose Q_ENUMS to QML?

 Thanks,
 Jerome P.
 ___
 Qt-qml mailing list
 Qt-qml@trolltech.com
 http://lists.trolltech.com/mailman/listinfo/qt-qml

___
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml