Re: [Qt-qml] Accessing a QAbstractItemModel in QML outside a view
Martin, thanks for the hint! Ok, I guess that would work. Not exactly straightforward though. I assume it will also work when I need to iterate over all items in a model to do some operation on all of them, but by indexing using something. Hm, I looked at the API and it seems I can't access items randomly from outside the view either. So the best way is to make a proper API in C++. Not ideal, but takes a lot less time than trying to do it in QML... On Dec 1, 2010, at 9:26 , martin.jo...@nokia.com martin.jo...@nokia.com wrote: Right now if you want to access data in your model in script, you will need to add methods to your model to allow that. For the specific case of showing data from the currentItem, you can expose the model data, e.g. ListView { Id: list delegate: Text { property variant data: model text: name } } Text { text: list.currentItem.data.name } BR, Martin. -Original Message- From: qt-qml-boun...@trolltech.com [mailto:qt-qml-boun...@trolltech.com] On Behalf Of ext Jan Ekholm Sent: Wednesday, 1 December 2010 4:55 PM To: qt-qml@trolltech.com Subject: [Qt-qml] Accessing a QAbstractItemModel in QML outside a view Hi, The subject says it all, apart from the context. Accessing a QAIM in a view (such as a ListView) is all nicely documented and works as expected. However, how can I access the same exposed C++ model outside a view? In my case I want to show a list of data and next to the list have some Text/Image items with more information about the selected item in the view. Totally normal stuff. Getting the index of the selected row is easy, the view gives me that. Getting the model instance is also easy, it's in the root context. However, getting data out of the model seems to be impossible. I've tried all kinds of ways to access the data but none works. However, if I look here: http://doc.trolltech.com/4.7/qdeclarativemodels.html#accessing-views-and-models- from-delegates it's seems that delegates can even write data to a model. This gives a somewhat perverse situation where you can inside delegates read and write to models but outside a delegate you can't even read data. So, this can't possibly be the case and there's something my thick brain just does not grok? I mean, models are one of the few ways you can get real data into a QML document, and not being able to actually access it makes it all feel somewhat silly. I can make extra methods on my subclassed QAIM on the C++ side to get data, but the point is that I should not have to do that, it ought to just work. Someone please give me some RTFM resource. Best regards, Jan Ekholm -- Jan Ekholm jan.ekh...@smultron.net ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml -- Jan Ekholm jan.ekh...@smultron.net ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
[Qt-qml] Accessing a QAbstractItemModel in QML outside a view
Hi, The subject says it all, apart from the context. Accessing a QAIM in a view (such as a ListView) is all nicely documented and works as expected. However, how can I access the same exposed C++ model outside a view? In my case I want to show a list of data and next to the list have some Text/Image items with more information about the selected item in the view. Totally normal stuff. Getting the index of the selected row is easy, the view gives me that. Getting the model instance is also easy, it's in the root context. However, getting data out of the model seems to be impossible. I've tried all kinds of ways to access the data but none works. However, if I look here: http://doc.trolltech.com/4.7/qdeclarativemodels.html#accessing-views-and-models-from-delegates it's seems that delegates can even write data to a model. This gives a somewhat perverse situation where you can inside delegates read and write to models but outside a delegate you can't even read data. So, this can't possibly be the case and there's something my thick brain just does not grok? I mean, models are one of the few ways you can get real data into a QML document, and not being able to actually access it makes it all feel somewhat silly. I can make extra methods on my subclassed QAIM on the C++ side to get data, but the point is that I should not have to do that, it ought to just work. Someone please give me some RTFM resource. Best regards, Jan Ekholm -- Jan Ekholm jan.ekh...@smultron.net ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] Modal dialogs in QML?
Two ideas: You could create a fully opaque Rectangle filling the whole screen with a centred, smaller Rectangle as child (the real visible dialog). But I guess opacity is inherited by the child ... maybe the smaller one it needs to be independent. Or you create a global property in the top Rectangle disabling (attached to) all Mouseareas in child items (except the dlg's) if the dialog is visible. Jan Am 24.11.2010 05:35, schrieb Bart Kelsey: 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? Bart ___ 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] Dynamically created items and properties
On Aug 24, 2010, at 8:48 AM, bea@nokia.com wrote: ... foo.qml: QML PropertyChanges: Cannot assign to non-existent property connectionTarget Oops, I left out an important part. The Connections object should have target: dummyId.connectionTarget to actually bind to the connectionTarget alias property. Also, change the PropertyChanges target to 'dummyId' instead of 'seenConnection', so that the connectionTarget alias is updated. This seems to create a binding loop. ... QML Connections: Binding loop detected for property target Perhaps I did it wrong, but if it's this hard to copy instructions verbatim and get them right, then the whole workaround kludge setup is already way too complex. I'll leave the errors as they are and put this down to can't be done with QML yet and look at it later when the rest is done. -- Jan Ekholm jan.ekh...@smultron.net ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] setting QDeclarative view using UI file of Qt
On Tuesday 24 August 2010 13:02:47 Kumar vaibhav wrote: ...vaibhav.qml... import Qt 4.7 Rectangle { width: 640 height: 480 MouseArea { id: mouse_area1 anchors.fill: parent onClicked: console.log(vaibhav), test.callfromqml() } } To me the , looks invalid. Perhaps something like: onClicked: { console.log(vaibhav); test.callfromqml(); } -- Students? barked the Archchancellor. Yes, Master. You know? They're the thinner ones with the pale faces? Because we're a university? They come with the whole thing, like rats -- -- Terry Pratchett, Moving Pictures ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] QDeclarativeItem subclasses and mouse events
On Thursday 05 August 2010 09:03:36 michael.bras...@nokia.com wrote: In tests/benchmarks/declarative there is a tool called qmltime that can be used to profile component creation costs. Running my N900: * the original QML tile took 2.13ms to create * the same tile with the 5 bindings removed (just assigning the values directly) took .35ms My default test map had 1500 hexes, which immediately brings just the item creation to over 3s, not including (I guess) the actual image loading or any other components. For this component, *none* of the bindings hit the binding optimizer, which is why removing them had such a large impact. We'll continue to expand the scope of the optimizer (so it hits more cases), as well as further optimize those that don't hit the optimizer in future releases, so hopefully these cases become fewer and fewer. That would perhaps means that binding to C++ properties is not covered by the optimizer? All the data for that item comes from C++, which also is the case for many other QML items in my crappy app. The above wouldn't account for the 3-10s load time you are seeing on the PC though, so maybe there are some additional factors in play for this particular case (but nothing jumped out at me). There are some other components too. Also, as the old Image loaded the icon asynchronously that likely also takes some time that perhaps does not show up in the above tool? For X11, also remember to use the raster or GL graphics systems for optimal QML performance. I've made raster default in my Qt:s since the -graphicssystem option became available. It was the best way to get reasonable visual performance from Qt4. I won't worry about that it takes some extra seconds setting up the actual game. N900 owners are already very used to hideously slow loading for any application, so they are not likely to even notice a 10s delay. I could try to play some funky music while it loads... -- Pets are always a great help in times of stress. And in times of starvation too, o'course. -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] enumerations in QML
On Thursday 05 August 2010 08:03:41 bea@nokia.com wrote: On 05/08/2010, at 2:45 PM, ext Gregory Schlomoff wrote: Isn't there a way to expose an enum to QML with qRegisterType or something? If an enum is exposed to Qt's Meta Object system using Q_ENUMS, the enum is automatically available to QML. This is mentioned in http://doc.qt.nokia.com/4.7-snapshot/declarative-tutorials-extending-chapt er4-custompropertytypes.html (but probably should be moved to some other reference documentation). I did my C++ enum just like that and it did not work at all. After some fighting and testing all combinations of foo.bar that I could think of on the QML side I have up an rewrote it to not need the enum on the QML side. There's a chapter Extending QML from C++ (or similar, my Assistant currently doesn't seem to show any QML docs at all (bug report added)) where the information from the tutorial would perhaps fit better? -- Many an ancient lord's last words had been: You can't kill me because I've got magic aaargh -- Terry Pratchett, Interesting Times ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] QDeclarativeItem subclasses and mouse events
On Tuesday 03 August 2010 04:55:46 Gregory Schlomoff wrote: Hello ! You may want to have a look at our code for drag and drop, it's working well: http://bitbucket.org/gregschlom/qml-drag-drop (and more specifically http://bitbucket.org/gregschlom/qml-drag-drop/src/tip/DeclarativeDragArea.c pp ) You seem to do nothing magical with your item either. Strange. But you also have no implementation of: virtual QPainterPath shape () const; virtual QRectF boundingRect () const; If I comment out my versions then I get lots of painting errors, the Flickable that contains the items is behaving very strangely etc. Your item seems to be non visual, perhaps that's why you don't need those methods? As I see shape() getting called but nothing else happen I suspect that there's something fishy going on in QDI regarding this. -- The trouble with being a god is that you've got no one to pray to. -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] QDeclarativeItem subclasses and mouse events
On Tuesday 03 August 2010 09:51:13 michael.bras...@nokia.com wrote: Hi, On 03/08/2010, at 4:27 PM, ext Jan Ekholm wrote: On Tuesday 03 August 2010 04:55:46 Gregory Schlomoff wrote: Hello ! You may want to have a look at our code for drag and drop, it's working well: http://bitbucket.org/gregschlom/qml-drag-drop (and more specifically http://bitbucket.org/gregschlom/qml-drag-drop/src/tip/DeclarativeDragAre a.c pp ) You seem to do nothing magical with your item either. Strange. But you also have no implementation of: virtual QPainterPath shape () const; virtual QRectF boundingRect () const; Note that QDeclarativeItem has a default implementation of boundingRect() based on the width/height of the item. I found my problem. Or, well, not found, but cured. I needed a total clean recompile for it to work. Then my shape() started working as it should and the event handlers were called as expected. Apparently the fact that my class changed base class from QObject to QDeclarativeItem was a change too big for qmake to pick up and a clean compilation was needed. However, I noticed that as I move the item to be a pure C++ item I also want to create it from the C++ side and later add to a Flickable in a QML file. Like this: ectangle { id: playfield Flickable { contentWidth: hexes.width contentHeight: hexes.height anchors.fill: parent // the C++ class which contains 100-1 C++ items of a Hex class Map { id: hexes } } } If I create a Map class on the C++ side, can I add it to the scene dynamically? I understand that a declarative thingie is not meant to be dynamic in any way, but I have to be a bit pragmatic. If the Map is created as above I can't refer to it from the C++ side, so, what I guess I want to do is something like: Map * map = new Map; map-setupContents(); map-doOtherSetup(); map-create1Hexes(); // now find the flickable and make it show my map QDeclarativeView * v = Flickable * f = v- f-setItem ( map ); // profit My rubbish little test app can be seen at: http://gitorious.org/tactics But most stuff there is totally crap so don't go copying any ideas or code, it's very likely to be buggy, wrong and useless. -- Voodoo is a very interesting religion for the whole family, even those members of it who are dead. -- Terry Pratchett Neil Gaiman, Good Omens ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
[Qt-qml] QDeclarativeItem subclasses and mouse events
Hi, I was recommended to make a C++ QDeclarativeItem subclass for my game map tiles to get better performance. This worked well and the class was easy to implement, register and get to work. However, I can't seem to get mouse press/release events to work, whatever I do the events aren't relayed to my items. The methods I try are: virtual void mousePressEvent (QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event); I guess I can make a MouseArea per item as I had before with my pure QML solution, but it's not ideal. The items are not rectangles in shape and it's not possible to have custom shapes for MouseArea. I see that the shape() method is called for the correct C++ item, so apparently something checks wether the mouse was pressed inside the C++ item, but I never get any event. Probably there's something trivial I'm missing here? I've looked through all the demos and examples, but none of the C++ items are interactive that I can see. Any hints as to where my failure to grok stuff would be? Kind regards, Jan Ekholm -- Five exclamation marks, the sure sign of an insane mind. -- Terry Pratchett, Reaper Man ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] Dynamically created items and properties
I tried to change the Unit item to really, really bind to the C++ properties using this change: Item { function createUnits (component) { if ( component.status == Component.Ready ) { // get all units, this is a C++ list of Unit* var unit_list = scenario.units.units; for ( var index = 0; index unit_list.length; index++ ) { // the c++ unit, a Unit* var unit = unit_list[index] // create a new item with the root Item as parent, see // the id property var item = component.createObject( units ); if (item == null) { console.log( Units.createUnits: failed to create unit ); } else { item.setup( index ) } } } else if (component.status == Component.Error) { // ugh } } function loadComponent () { // load the component var component = Qt.createComponent(Unit.qml); // create the real items createUnits( component ); } Component.onCompleted: loadComponent(); id: units } And the Unit.qml file would have this function to perform the binding: Image { function setup (index) { x = scenario.units.units[index].x y = scenario.units.units[index].y source = scenario.units.units[index].icon unit_id = scenario.units.units[index].id } property int unit_id ... } The scenario.units.units[index] maps to a real C++ Unit* and that code has worked fine in several other contexts. Still, no go. The item just does not react to property changes. -- Pets are always a great help in times of stress. And in times of starvation too, o'course. -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
[Qt-qml] Dynamically created items and properties
Hi, Is is a known bug that items that are created dynamically do not handle properties properly? I create lots of items using Qt.createObject() as they can not be defined at design time. Initially I used a Repeater to set up the items and that worked well, the item properties were fully bound to the Q_PROPERTY properties of the C++ objects they represented. However, you can not dynamically destroy items created using a Repeater (or so the docs have me believe), so something else was needed. So, now I set up my game pieces like this: import Qt 4.7 Item { function createUnits (component) { if ( component.status == Component.Ready ) { // get all units, this is a C++ list of Unit* var unit_list = scenario.units.units; for ( var index = 0; index unit_list.length; index++ ) { // the c++ unit, a Unit* var unit = unit_list[index] // create a new item with the root Item as parent, see // the id property var item = component.createObject( units ); if (item == null) { console.log( Units.createUnits: failed to create unit ); } else { // bind all properties to the C++ object item.x = unit.x * 48 + ( unit.y % 2 ) * 24 item.y = unit.y * 36 item.source = unit.icon item.unit_id = unit.id } } } else if (component.status == Component.Error) { // ugh } } function loadComponent () { // load the component var component = Qt.createComponent(Unit.qml); // create the real items createUnits( component ); } Component.onCompleted: loadComponent(); id: units } The Unit.qml file basically contains an Image {} with a few behaviours and a mouse area and has worked fine. This setup works so far that the Unit items get created and the correct initial properties are set. They show up at the right place and with the right image loaded. It all goes wrong when the C++ object changes, say, its position. The dynamically created items have their x and y properties bound to these C++ properties: Q_PROPERTY( int x READ getX NOTIFY positionChanged ); Q_PROPERTY( int y READ getY NOTIFY positionChanged ); This worked fine with the Repeater created items. The Unit items nicely followed the C++ object's properties. However, the items created with the above code will totally ignore any property changes. No amount of emitting positionChanged will move the dynamic items. So, my question is now, is this: 1. a bug in my code and I'm somehow not doing it right (lets hope for that) 2. properties in dynamic objects should not work (argh!) 3. properties in dynamic objects should work but are broken 4. a combination of the above 5. none of the above As it is I can't get dynamic creation destruction and properties to work at the same time and that more or less makes my whole silly game impossible to do. Destroying items by moving them outside the game area, hiding them etc is just a very ugly kludge and I'd like to avoid resorting to stuff like that until nothing else works. [Of course, one way would be to dynamically create a QML file with all the needed Unit items when I load the game data on the C++ side. This file would be created before the QML side is even initialized. But this would be an epically ugly kludge that should fall into the 12th layer of hell.] Best regards, Jan Ekholm -- He says gods like to see an atheist around. Gives them something to aim at. -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
[Qt-qml] Changes to how QML files can import other QML files?
Hi, I have a small stupid, dumb project that I haven't worked on for a few weeks. When I last touched it at the end of June all worked fine and there were no issues. Now, all my import statements in my QML files fail. The files have imports like: import Qt 4.7 import Buttons.qml import Map.qml ... Each of my own QML file gives errors like: file:///home/chakie/prog/c++/tactics/qml/Tactics.qml:3:1: Buttons.qml: no such directory import Buttons.qml Changing the import order gives similar errors for all other files. So something has changed and I can't find any mention about it in the docs, blogs, this mailing list or IRC. It's a tiny bit worrying to have perfectly fine code bit rot into oblivion in just some weeks. This did work fine in June. The C++ executable that drives it all is located in: /home/chakie/prog/c++/tactics/ and the QML files are all in: /home/chakie/prog/c++/tactics/qml/ Randomly adding paths with: void QDeclarativeEngine::addImportPath ( const QString path ) does not seem to help either. The main QML files are not compiled in as resources, as that does not work properly due to QMake(?) bugs. They are simply loaded from disk when needed. My guess is that there have been changes to where QML files are allowed to be and I need to do something to something to get something to find them again. Also using complete paths for the import lines does not work. Any hints? Would it be better to wait some months to let everything stabilize before trying QML for real apps? Kind regards, Jan Ekholm -- Pets are always a great help in times of stress. And in times of starvation too, o'course. -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml
Re: [Qt-qml] Audio and Video
On Thursday 20 May 2010 10:41:56 kai.koe...@nokia.com wrote: qt-qml-boun...@trolltech.com wrote: defaultServiceProvider::requestService(): no service found for -com.nokia.qt.mediaplayer My Qt version is 4.7 Beta1 My best advice for you is to try downloading the Qt APIs for Mobile Development: https://qt.nokia.com/products/appdev/add-on-products/catalog/4/new-qt-apis /mobility , and add them to your Qt installation. But it seems they're providing only source code so far, so you'd have to compile the library yourself ... You might consider also asking on the Qt-Mobility-Feedback mailing list http://lists.trolltech.com/mailman/listinfo/qt-mobility-feedback for guidance. The multimedia stuff in Qt-Mobility does not really work at all at the moment, at least I have no idea how to get it to find any of its plugins. I see the same above error message for all the multimedia examples in Qt-Mobility. Not that this has anything to do with QML. I was fortunate to build my media stuff using a C++ based QMediaPlayer, so all that was needed for me was to add some stuff to my .pro file and recompile and the multimedia stuff was found again. Well, at least it compiles, it does not yet *play* anything. :) -- And it came to pass that in time the Great God Om spake unto Brutha, the Chosen One: Psst! -- Terry Pratchett, Small Gods ___ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml