meg@akademy2017

Hi there,

It's been a while since my last post over here. After being drained with a lot of work on the very first edition of QtCon Brasil, we all had to take some rest to recharge our batteries and get ready for some new crazinesses.

This post is a short summary of the talk I presented at Akademy 2017, in the quite sunny Almería in Spain. Akademy is always a fascinating experience and it's actually like being at home, meeting old friends and getting recurrently astonished by all awesomeness coming out of KDE community :).

My talk was about architecting Qt mobile applications (slides here | video here). The talk started with a brief report on our Qt mobile development experiences at IFBa in the last two years and then I explained how we've been using lean QML-based architectures and code generators to leverage the productivity and provide flexible and reusable solutions for Qt mobile applications.

Our approach ‒ named Meg ‒ is defined by two major components: a lean dynamic QML-based architecture for Qt mobile applications and a code generator for enabling the creation of modular RESTful servers and Qt mobile applications. Meg provide a Ruby-based CLI, built on top of Thor CLI framework, with templates specified in ERB (Embedded RuBy). We also designed a nice architecture for the generator itself, so that new templates can be defined as new Thor modules. The framework that implements the lean architecture we designed for Qt mobile applications already provides a JSONListModel QML object, making it easier to implement RESTful Qt clients.

The following templates are currently available:

  • Sinatra RESTful server with modular architecture (sinatra-server)
  • Ruby Sinatra RESTful service plug-in (sinatra-service-plugin)
  • Simple Qt mobile app with plugin-based architecture (simple-app)
  • Qt mobile RESTful app with plugin-based architecture (restful-app)
  • Qt mobile RESTful client plug-in (restful-client-plugin)

You're welcome to try it :) Here is what you need to do:

* git clone https://github.com/sandroandrade/meg.git
* install ruby
* run ‘gem install bundler’
* Run ‘bundle install’
* Meg CLI is available in ‘./bin/meg’

Creating a simple plugin-based QML application

So, these are the steps to create a simple plugin-based QML application using Meg:

1. Create a new project using simple-app as project type (template):
./bin/meg new SimpleApp -t simple-app
2. Create a new plugin, for example, to display students information:
./bin/meg generate plugin students -t basic-plugin -a simpleapp/
3. Create another plugin, for example, to display teachers information:
./bin/meg generate plugin teachers -t basic-plugin -a simpleapp/

In step 1, we create a new project in the simpleapp directory, using the basic-plugin template (-t option). In steps 2 and 3, we create two plugins (students and teachers), using the basic-plugin template and install them at simpleapp directory. After that, your application is available at simpleapp directory and can be built by a normal qmake/make run.

Here is what you get out of those steps:

Creating a Sinatra-based RESTful server

Besides automating the creation of Qt-based mobile clients, Meg also provides some templates for generating RESTful servers based on Sinatra Ruby microframework. As in the client-side, we also designed a plugin-based architecture for the RESTful server, where new services are provided by separate modules. Here are the steps to create a new RESTful server:

1. Create the server project:
./bin/meg new myserver -t sinatra-server
2. Create a plugin for handling CRUD operations for an application for visualizing a conference program:
./bin/meg generate plugin Conference -t sinatra-service-plugin -a myserver/ acronym:string name:string city:string country:string venue:string start_date:datetime end_date:datetime
3. Create a similar plugin for handling CRUD operations for handling speakers:
./bin/meg generate plugin Speaker -t sinatra-service-plugin -a myserver/ name:string affiliation:string shortbio:string

To run the server you first need to setup the database:

$ cd myserver
$ rake db:migrate

And populate some data:

$ sqlite3 db/development.sqlite3
insert into conferences values (1, 'QtCon-BR', 'QtCon Brasil', 'São Paulo', 'Brasil', 'Espaco Fit', '2017-08-18 09:00:00', '2017-08-20 18:00:00');
insert into conferences values (2, 'Akademy', 'Akademy', 'Berlin', 'Germany', 'BCC', '2017-03-01 09:00:00', '2017-03-03 18:00:00');
insert into conferences values (3, 'Conf.KDE.in', 'Conf.KDE.in', 'Guwahati', 'India', 'IIT', '2017-03-10 09:00:00', '2017-03-12 18:00:00');
insert into speakers values (1, 'Our beloved Konqi', 'KDE', 'Konqi is awesome');
insert into speakers values (2, 'Dirk Gently', 'Adams', 'He is a holistic detective');

Now, you can start the server:

$ ruby myserver.rb

Creating a Qt-based RESTful client

Creating a Qt-based RESTful client for our server is also quite simple:

$ ./bin/meg new MyApp -t restful-app
$ ./bin/meg generate plugin conferences -t restful-client-plugin -a myapp -i name -c university acronym:string name:string city:string venue:string start_date:datetime end_date:datetime
$ ./bin/meg generate plugin speakers -t restful-client-plugin -a myapp -i name -c microphone name:string affiliation:string shortbio:string

Such commands create a new Qt mobile project, using the restul-app template. Then, two RESTful client plugins for the aforementioned services are created and installed in the project directory. You can now build your Qt mobile client and, once started the server, this is what you get out from it:

So, that's all folks! We hope this can improve somehow the development workflow and of RESTful-based Qt mobile applications. This is a one-year project being carried out at IFBa by myself and Eliakin Costa. Hopefully, we'll get back with some news soon.

See you!