Mbarcode Plugin Tutorial - Qt SDK

This tutorial will try to guide you through the process of creating an MBarcode plugin using the Nokia Qt SDK. The aim of this tutorial is to give you the knowledge necessary to create a basic plugin for MBarcode without having to rely on Scratchbox.

If you are looking to develop a plugin for mBarcode using Scratchbox then please see this tutorial: Mbarcode_Plugin_Tutorial

Prerequisites
In this tutorial we'll be using Qt together with C++ to connect to the mBarcode plugin framework. Unlike the other tutorial this one is aimed at using the Nokia Qt SDK. This can be downloaded from Nokia's website at qt.nokia.com/downloads

You must have: * Nokia Qt SDK qt.nokia.com/downloads * An N900 (may work on older tablets as well) * A linux OS (haven't tested this on Windows but it would probably work with a few tweaks) * Some basic C++ knowledge, though you can probably do this without any

Initial Setup
To start with you will need to install the Nokia Qt SDK, this process is very self explanatory and easy to follow. Just make sure you install the correct version of the SDK, it will have Qt Simulator and the Maemo libraries bundled with it. Provided you download the SDK from the above link (qt.nokia.com) you shouldn't have any problems.

Getting the required headers
Since the Nokia Qt SDK doesn't currently support installing packages in any easy manner the easiest way to do this would be to install "mbarcode-dev" on your N900 and then copying the headers. This can be done by opening a terminal (Ctrl + Shift + X) and typing the following: sudo gainroot apt-get install mbarcode-dev cp /usr/include/mbarcode-qt/* /home/user/MyDocs/ That should copy the required header files to your MyDocs directory on the N900, which you can then access by putting it into Mass Storage mode and copying the header files. You should get the following: These files then need to be copied onto your development machine. Copy them into the following folders on your computer:
 * maemobarcodewindow.h
 * pluginaction.h
 * plugininterfaces.h
 * /usr/include/mbarcode-qt/*
 * /home/ /QtSDK/Maemo/sysroots/ /usr/include/mbarcode-qt/*

Creating the Project
To create the project, launch Qt Creator and click New Project. Select "Empty Qt Application" as the type (under "Other Project"). When asked make sure that you choose to include the versions of Qt for Maemo and the Qt Simulator. This will allow you to compile your plugin for your phone and eventually package it.

Setting up your .PRO file
The .PRO file tells Qt what to do with your project, so that will be the first thing we are going to set up. The easiest way to do this is to open up your .PRO file and paste the following code into it (overwriting everything else)

Next we are going to add our deployment script, this in necessary for creating the DEB file used to install your plugin. Right click on your project's name in the left hand side of Qt Creator and choose "Add New". Choose "Text File" from the "General" category and name the file deployment.pri. When that is done you just need to copy the following into your new file. Don't worry about what it does, it is a slightly modified version of the standard deployment.pri file created when you create a new Qt Mobile Application in Qt Creator.

The final step is to go back into your .PRO file and remove the line that reads: OTHER_FILES += \ deployment.pri

Creating your Plugin
Now that you have created the files needed by Qt Creator for packaging your plugin we can start creating the actual plugin. To start off we are going to need to create a new C++ class. This is done in the same way as you created your deployment.pri file. Give it the name "PluginLogic" and click OK.

pluginlogic.h
Inside the pluginlogic.h file paste the following code. This will form the basic structure for our plugin and should give you a good idea of what we are going to do with it.

pluginlogic.cpp
We will also need to create the actual code that goes in our pluginlogic.cpp file. This code will do the work of the plugin. I am not going to add it here since using the header you should be able to create it easily enough. It will be added at a later stage though.

plugin.h
The next thing we will need for our plugin is the class that handles loading of the plugin files. This class we will call Plugin and should be created the same way you created "PluginLogic". As with "pluginlogic.h" you just need to copy the following code into your header file:

plugin.cpp
And now we are almost at the final part of creating the plugin, this is where we add the code that initializes the plugin for use by mBarcode. You can copy the following code into it, just make sure to change the plugin name at the bottom to make sure you don't break something ;)

Packaging
Okay, now that our plugin is complete you can try compiling it. It should do so without any difficulty (provided you didn't break something). Once it has been built you will need to open up your project's folder and open the "qtc_packaging/debian_freemantle" folder. Inside this folder are the files that will be used to create your DEB file. You can read more about what they do here but in the mean time I will try to give you a rough guide through. Basically you need to edit the control file to add information about your package. Simply change whatever needs changing (usually enclosed in &lt; and &gt;). You may also want to change the copyright, README and changelog files. Do NOT edit rules or compat though.

Once you have edited the package's details to your liking go back into Qt Creator and choose Maemo as your build target. To do this simply click on the picture of a computer in the bottom left of the window and choose the Maemo option. When that is done click on the Build menu (top of the screen) and choose "Deploy ". This will cause Qt Creator to start building your application and when it is done it will try to send it to your phone. If your phone isn't connected (which I assume it isn't since you have been following this tutorial...you have haven't you?) it will fail on the last step. Don't worry, this is not a problem because if you open up your projects folder you should see a folder called  -build-maemo and inside that should be your shiny new DEB file.

Copy it onto your N900 and install it using dpkg like so: sudo gainroot cd  dpkg -i 

The final step is to open up MBarcode and scan a barcode...with any luck your plugin will show up and process the barcode.

--spartan563 23:04, 20 May 2011 (UTC)