[Interest] Project structure for multi-platform mobile devices

Luca Bonifacio luca.bonifacio at bbv.ch
Wed Apr 23 10:18:45 CEST 2014


Hi everyone



Actually, I'm getting serious problems by setting up a Qt/QML project integrating also unit tests for a multi-platform mobile application. The idea is to set up a project skeleton for the development of applications, which will run on Android and iOS; and at the same time, the unit tests will be executed on a continuous integration server.

For that purpose, I initially defined a subdirs project containing two projects: one for the application and one for the unit tests.

The HelloWorld application ran without any problems on both platforms. Also the unit test written in QML worked fine.



The problems began when I started to write my unit tests for the QML file that embeds C++ objects. By running the unit tests on the QML component that uses C++ objects, errors are displayed on the console: the C++ objects are not found. That makes also sense cause the C++ objects are set in the main.cpp file by using setContextProperty on my root context view. To get around to the problem I decided to do the following:

1.            Mock the C++ objects in my QML unit tests, and

2.            Add a new unit tests project for the C++ part.



For the first item, unfortunately, I didn't find any information or example about how to mock a C++ object in QML.



For the second item, as I want to test the C++ objects, I decided to split my application into two parts. One part includes the application core (everything apart the main), which is statically built, instead the second part includes just the main functions which links against the application core and executes it. In the same way, I'm able to run my unit tests for my C++ objects.



Finally, I get the following project structure:

*             application-core               static built

*             application-app                 links against the application-core

*             unit-tests-qml                   tests only QML files of application-core

*             unit-tests-qt                      links against the application-core and tests only C++ objects



The new application runs without problem on Android devices, instead on iOS devices I get an error message: module "QtQuick" plugin "qtquick2plugin" not found.



Here my questions:

1.            Is it possible to mock C++ objects or others components in QML? If yes, how?

2.            Is the structure of my project correct? Or generally, how to structure complex projects?



Thank a lot in advance for every kind of helps or suggestions.



Best regards



Luca Bonifacio

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140423/3b04d669/attachment.html>


More information about the Interest mailing list