PDA

View Full Version : Challenges in migration of Qt 4.8.2 project into Qt 5.7 and above



Anjali Srivastava
3rd February 2019, 09:32
Hello,
• My project requirement is to display some moving objects(images with text) in one area of screen and list of objects needs to be shown in a tree view in another area of the screen, on selection of any object, detail of that object will be shown in other view(line edit, combo box, table) and particular object will be highlighted (selection) in the tree view. With the moving objects, Grids and Ellipse are also needs to be displayed.
• So we followed layer type architecture like one graphics item on the above of another graphics item and background of each graphics item is transparent so each object is visible.
• For the above requirements we used Qt 4.8.2 in which model view architecture and Qt graphics frame work is used.
• To display moving objects, we have created a parent graphics rectangle item and added this into graphics scene.
• To support model view architecture in graphics view frame work, we used QDeclarativeItem.
• So now a QGraphicsRect item is the parent of QDeclarativeItem and successfully added in the QGraphicsScene.
• Now we planned to upgrade to Qt version i.e. Qt 4.8.2 to Qt 5.7 and above.
• The challenges we are facing is to change the QDeclarativeItem, when we changed it by QQuickItem then objects are not displayed in the scene because QGraphicsRect item cannot be the parent of QQuickItem.
• We also tried QQuickPaintedItem but the result was same.
• QQuickView is some how working but our screen is not loading correctly, some xcb warning is coming in the terminal.
• Now we used QQuickWidget and added it directly in QGraphicsscene but it’s background is not getting transparent so Grid and Ellipse are not visible.
• The properties and signals of Qml file is also not accessible through QQuickWidget.What will be the best solution???
• If we will migrate the whole project in Qml then what is the replacement of QGraphicsscene and if we want to add QGraphicsItems in Qml, will it be possible??? Because we have some vendors and they are developing few objects as a QGraphicsItems.

anda_skoa
3rd February 2019, 09:45
Your problem comes from using QDeclarativeItem in a QGraphicsScene.

While a Qt4 QtQuick Scene is essentially a QGraphicsScene, it is very hacky to then use that quick scene as if it where a normal QGraphicsScene.

If your only use case for using the declarative engine is to have a model/view access API, I would recommend using standard QGraphicsScene and just doing the model access yourself.

If you are using the declarative framework for the actual item construction, I would recommend not interacting with the QGraphicsScene from C++. This will then nicely map to using Qt5 QtQuick.



Now we used QQuickWidget and added it directly in QGraphicsscene

You would be using the QQuickWidget instead of the QGraphicsView, not as a part of it


Cheers,
_

Anjali Srivastava
4th February 2019, 04:14
Hi anda_skoa,

If you are using the declarative framework for the actual item construction, I would recommend not interacting with the QGraphicsScene from C++. This will then nicely map to using Qt5 QtQuick.

Some of the items are created as QGraphicsItem and some are QDeclarativeItem, If we will not use QGraphicsScene, then how will we add QGraphicsItems to the scene?

You would be using the QQuickWidget instead of the QGraphicsView, not as a part of it

QGracphicsView and QGraphicsScene is already there and we used QQuickWidget to show the QML items into the scene.

anda_skoa
4th February 2019, 13:06
Some of the items are created as QGraphicsItem and some are QDeclarativeItem, If we will not use QGraphicsScene, then how will we add QGraphicsItems to the scene?

What kind if items do you create as graphics items?

It might be possible to just make custom declarative items and create all items from QML.



QGracphicsView and QGraphicsScene is already there and we used QQuickWidget to show the QML items into the scene.

So currently you have a QDeclarativeView as an item in your QGraphicsScene?

Cheers,
_

Anjali Srivastava
5th February 2019, 10:21
What kind if items do you create as graphics items?

Grids and Ellipses are created as graphics item and in future vendor company will also create some items as graphics Item.


It might be possible to just make custom declarative items and create all items from QML.

In Qt 4.8.2 we used QDeclalativeItem to create some objects in QML and added it to QGraphicsScene. But now in Qt 5.7 how will we create it?


So currently you have a QDeclarativeView as an item in your QGraphicsScene?

No, We are not using QDeclarativeView. We used QQuickWidget to access Item form QML file and added it to QGraphicsScene.

anda_skoa
5th February 2019, 11:17
Grids and Ellipses are created as graphics item and in future vendor company will also create some items as graphics Item.

Should be trivial to create these as custom QDeclarativeItems



In Qt 4.8.2 we used QDeclalativeItem to create some objects in QML and added it to QGraphicsScene.

Ah, ok, very hacky.

If you use a QDeclarativeView instead then you can use the same approach when moving to a QQuickWidget.




We used QQuickWidget to access Item form QML file and added it to QGraphicsScene.

Well, that's not possible since Qt5 QQuickItems are not QGraphicsItems.
QtQuick is rendered with an OpenGL based scene graph.

As far as I understood your setup you have these options:

1) Remove the usage of QML

2) Keep using QGraphicsView and just use QQmlEngine with custom types to create QGraphicItem based objects in QML

3) Move the Qt4 version to use QDeclarativeView and custom QDeclarativeItem and then port that almost unchanged to QtQuickWidget and custom QQuickPaintedItems.

Cheers,
_

Anjali Srivastava
7th February 2019, 04:23
Should be trivial to create these as custom QDeclarativeItems

1) Remove the usage of QML

2) Keep using QGraphicsView and just use QQmlEngine with custom types to create QGraphicItem based objects in QML

3) Move the Qt4 version to use QDeclarativeView and custom QDeclarativeItem and then port that almost unchanged to QtQuickWidget and custom QQuickPaintedItems.


_


Yes I think you are right, If I follow the point two then could you provide any example or link for the same.

anda_skoa
7th February 2019, 12:08
The QML engine (in both Qt4 and Qt5) can essentially create instances of any class that is derived from QObject (directly or indirectly).

So for example if you have a class that derives from QGraphicsObject you should be able to register that with the QML engine's type system and then use in QML like any of the "built-in" types.

http://doc.qt.io/archives/qt-4.8/qdeclarativeengine.html#qmlRegisterType
http://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterType

Cheers,
_